Tuesday, May 23, 2017

SAS Macro – U-Turn (SAS) (Pt. 3)

This macro is to be utilized in tandem with the macro detailed in the previous article.

Already, from utilizing the Splitter Macro, we have separated all duplicate entries from the original data set so that they are contained in unique and separate sets. Next, utilizing the Namer Macro, we renamed all of the separate data set variables. While these are novel concepts, for the data to have any real useful purpose, it must be re-joined to the original set.

The goal is to create a set in which data entries that contain similar unique primary identifiers, have their entries listed as additional variables within the same observation. This sounds much more complicated than it actually is.

To achieve this goal, we will be utilizing the U-Turn Macro. The code can be found below:

%macro uturn;

%do i = 1 %to 3; /* Number of Dupout sets */

proc sql;
create table Datasetb1 as
select a.*, b.*
from Datasetb1 as a left join dupout&i as b
on a.VARA = b.VARA&i
;
quit;

%end;

%mend;


The “i” macro variable must be modified to the total number of dupout sets created by the splitter macro.

Illustrated, what is occurring is shown below:


If you have followed the steps properly by compiling and running the macros described throughout the previous articles, your data should resemble our example set:


In the next article, I will demonstrate another macro which performs an-unrelated function as it pertains to our previous examples.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.