BookmarkSubscribeRSS Feed
rdouble
Calcite | Level 5

I have a SAS data set t3. I want to run a data step inside a loop through a set of variables to create additional sets based on the variable value = 1, and rank two variables bal and otheramt in each subset, and then merge the ranks for each subset onto the original data set. Each rank column needs to be dynamically named so I know what subset is getting ranked. I know how to do proc rank and macros basically but do not know how to do this in the most dynamic way inside of a macro. Can you assist?

%macro dog();

data new;
set t3;
ARRAY Indicators(5) FirstVar--LastVar;

/*create data set for each of the subsets if firstvar = 1, secondvar = 1 ... lastvar = 1 */

/*for each new data set, rank by bal and otheramt*/
/*name the new rank columns [FirstVar]BalRank, [FirstVar]OtherAmtRank; */

/*merge the new ranks onto the original data set by ID*/
%mend;

%dog()

The Proc rank section would be something like this, but I would need the rank columns to have information about what subset I am ranking.

proc rank data=subset1 out=subset1ranked;
   var bal otheramt;
   ranks bal_rank otheramt_rank;
run;
2 REPLIES 2
ballardw
Super User

Example data?

 

Not going to make up fake data as there seems to be a high likelihood of getting such that won't behave like yours.

 

 

 

rdouble
Calcite | Level 5

sample would be something like this:

data WORK.t3(label='sample');
   infile datalines dsd truncover;
   input id:8. bal:32. otheramt:32. firstvar:32. secondvar:32. lastvar:32.;
 datalines;
 444 581 100 1 . 1
 555 255 200 1 1 1
 777 666 300 . . 1
 ;;;;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 297 views
  • 0 likes
  • 2 in conversation