Log
MPRINT(NEWVARS): data _null_;
MPRINT(NEWVARS): set teams end=end;
MPRINT(NEWVARS): count+1;
MPRINT(NEWVARS): call
symputx('macvar'||left(count),compress(color)||compress(team_name)||"Total");
MPRINT(NEWVARS): if end then call symputx('max',count);
MPRINT(NEWVARS): run;
NOTE: Numeric values have been converted to character values at the places given
by:
(Line):(Column).
863:77
NOTE: There were 5 observations read from the data set WORK.TEAMS.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
MPRINT(NEWVARS): data teamscores;
MPRINT(NEWVARS): set teams end=end;
MPRINT(NEWVARS): if _n_=1 then do;
MPRINT(NEWVARS): GreenCricketsTotal=sum(of game1-game3);
MPRINT(NEWVARS): retain GreenCricketsTotal;
MPRINT(NEWVARS): keep GreenCricketsTotal;
MPRINT(NEWVARS): end;
MPRINT(NEWVARS): if _n_=2 then do;
MPRINT(NEWVARS): BlueSeaOttersTotal=sum(of game1-game3);
MPRINT(NEWVARS): retain BlueSeaOttersTotal;
MPRINT(NEWVARS): keep BlueSeaOttersTotal;
MPRINT(NEWVARS): end;
MPRINT(NEWVARS): if _n_=3 then do;
MPRINT(NEWVARS): YellowStingersTotal=sum(of game1-game3);
MPRINT(NEWVARS): retain YellowStingersTotal;
MPRINT(NEWVARS): keep YellowStingersTotal;
MPRINT(NEWVARS): end;
MPRINT(NEWVARS): if _n_=4 then do;
MPRINT(NEWVARS): RedHotAntsTotal=sum(of game1-game3);
MPRINT(NEWVARS): retain RedHotAntsTotal;
MPRINT(NEWVARS): keep RedHotAntsTotal;
MPRINT(NEWVARS): end;
MPRINT(NEWVARS): if _n_=5 then do;
MPRINT(NEWVARS): PurpleCatsTotal=sum(of game1-game3);
MPRINT(NEWVARS): retain PurpleCatsTotal;
MPRINT(NEWVARS): keep PurpleCatsTotal;
MPRINT(NEWVARS): end;
MPRINT(NEWVARS): if end then output;
Output
Blue Red
Green Sea Yellow Hot Purple
Crickets Otters Stingers Ants Cats
Total Total Total Total Total
25 23 28 26 27
Example 7: Using a Macro to Create New Variable Names from Variable Values 461