I'm new to this forum. Can you advise how to create a month/year variable using a macro? I have individual monthly files that I will merge together to look at trends. However when I try the code below, I either get missing data or if I turn it into a character variable, the "&i." becomes the variable. I'd appreciate any guidance you can send my way. Thanks!
%macro date;
%do i = 4 %to 12;
data total_&i._2009;
set tier.total_&i._2009;
date = &i._2009;
%end;
run;
%mend date;
%date
Reviewing your code, I believe that you are attempting to assign "date" as a SAS DATE (numeric type) variable, possibly? Although you have no FORMAT statement defined.
You may need to look at using the MDY function to assign your SAS DATE variable and also use a FORMAT statement to assign "date" to the desired output format display.
Scott Barry
SBBWorks, Inc.
Message was edited by: sbb
Perhaps you can read all the monthly files into one data set and create a month flag in one step.
[pre]
libname tier '.';
data tier.total_4_2009 tier.total_5_2009 tier.total_6_2009 tier.total_7_2009 tier.total_8_2009;
do j = 1 to 4;
output;
end;
run;
data total;
set tier.total_: indsname=indsname;
date = input(cats('01',substr(indsname,index(indsname,'_'))),mmddyy12.);
format date yymm.;
run;
proc print;
run;
[/pre]