The first macro that I will be demonstrating is the splitter macro. This macro was created to help with the proper transposition of data observations contained within SAS data sets.
Ex. After:
The Method:
/* Create a copy of the original data set */
Data DATASETB1;
Set SETA;
Run;
Next, you will need to remove duplicate entries from the copy of the original data set. Make sure to sort based on a primary and unique identifier.
Proc Sort Data = DATASETB1 nodupkey dupout= DupOut1;
By VARA;
Run;
TABLES VARA;
RUN;
We are now ready to create and compile the macro, the code for which can be found below:
%macro splitter;
%do i = 1 %to 2; /* Highest frequency of unique re-occuring variable observation (VARA in our example) minus 2 */
%let h = %eval(&i+1);
proc sort data = DupOut&i nodupkey dupout= DupOut&h;
by VARA;
run;
%end;
%mend;
What this code seeks to achieve is the separation of duplicate values from the initial data set and the establishment of separate data sets, each containing a unique list of entries. Such as the illustration below demonstrates:
In the next article, we will review another macro which will help us in re-naming the variables of the newly created data sets. Once we have achieved this step, we can then begin re-assembling the separated data into a single set.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.