05-19-2015 04:03 PM
I have a simple macro question; if anyone has better sources to read up on macros, I would also appreciate it (I've been reading up a bit on google, but can't seem to find my error here)
I have two datasets called: data.neds09merge1 and data.neds10merge1
I want to add a variable for each year (2009, 2010) for the corresponding data sets above. So Data.neds09merge1 will have 2009 for everyone in the variable "year," and data.neds10merge1 will have 2010 for everyone in the variable "year."
Then, I want "yearz" to be 09 or 10, corresponding to the 2009 and 2010.
So basically I'm trying to do this but make a macro for it
year = 2009;
year = 2010;
but for some reason my macro is giving me trouble.
year = 20&yearz;
%stack(set = one, year = 09);
%stack(set = two, year = 10);
The error I get:
WARNING: Apparent symbolic reference MERGE not resolved.
I think it has something to do with the & after "year" and preceding "merge1." I'm not 100% sure though. Thoughts?Thanks! -Gina
05-19-2015 04:27 PM
You don't have a macro variable &merge1
You also seem to have spelling differences, in one place the macro variable is yearz, and other places it is &year
05-19-2015 06:52 PM
Unless you have someone dictating a policy to use 2 digit years in file/dataset names I would strongly recommend consider naming the original datasets as neds2009merge.
Then you don't have to calculate such things as 20+&year. Also it will make looping over datasets with macros or using call execute easier:
%do year=2008 %to 2012;
proc freq data=data.neds&year.merge1;
<other common code>
for a rough example.
05-20-2015 01:29 AM
set data.neds&year.merge1; *the dot after year terminates the macro variable name and signals to the macro interpreter that the following constitutes "plain" program text not to be treated by it;
year = 20&year;
05-20-2015 04:40 AM
I am not entirely sure what the point of the macro and all the code is. Why not just do:
set neds09merge1 (in=a) neds10merge1 (in=b);
if a then year=2009;