Posts

Showing posts with the label Macro for Sorting the Datasets

macro for sorting the the datasets

MACRO FOR SORTING: Rather than using the Proc Sort procedure all the time..... you can just use the following macro.... and call it when you req... to sort any SAS dataset..... EXAMPLE1: %macro srt(dtn,keyvar); proc sort data =&dtn; by &keyvar; run; %mend srt; %srt (ie,PT IEORRES); *the above step will tell SAS to sort the IE dataset with the by variables PT and IEORRES respectively. EXAMPLE2: *Sometimes we need to create an output dataset during the sorting process i.e in the Proc sort step in such a case use the below macro to do the same; %MACRO SORT(IN=,VAR=,OUT=); PROC SORT DATA=&IN OUT=&OUT; by &VAR; RUN; %MEND SORT; %SORT (IN=CEC1,VAR=PT,OUT=CEC2); %SORT (IN=DERIVE.HEADER,VAR=PT,OUT=HEADER1); EXAMPLE3: *Sometimes we need to use the NODUPKEY option to delete the duplicate observations in the dataset in such a case use the below macro to do the same; % MACRO SORT(IN,VAR,OUT,OPTN); PROC SORT DATA =...