I want to create an output dataset using a date suffix.
I am simplifying here and my program is long, but this is a simple problem, I just can't figure it out.
%let = import_date = 20180911.
Later, I name my output dataset:
data baseline_&import_date.;
set temp5;
run;
Result is a dataset called baseline_20180911.
Later, I want to reference this dataset in a bunch of procedures and I don't want to hardcode the name of the dataset into my program.
I also do not want to have to type this long name each time I reference the dataset:
proc freq data=baseline_&import_date.;
table fred;
run;
I want to use a new %let statement before my freqs/means/etc.
%let infile = baseline_&import_date.
proc freq data=&infile;
table fred;
run;
But of course I cannot do this because using this syntax I can't assign a macro with a macro unless I do something more. Not sure what it is though...
Thanks.
You can do all the things you are trying to do. However, you need to correct the syntax of the %LET statements. The first one has an extra equal sign and an extra period at the end. And both are missing a semicolon. Other than that, you can certainly use the value of one macro variable when defining a new macro variable:
%let import_date = 20180911;
%let infile = baseline_&import_date.;
Outside of that, is something not working?
Look up the SYSLAST automatic macro variable.
After your data set add a line:
%let infile = &syslast.;
You can do all the things you are trying to do. However, you need to correct the syntax of the %LET statements. The first one has an extra equal sign and an extra period at the end. And both are missing a semicolon. Other than that, you can certainly use the value of one macro variable when defining a new macro variable:
%let import_date = 20180911;
%let infile = baseline_&import_date.;
Outside of that, is something not working?
I think this is the possible flaw in your understanding, except I'm not 100% sure what it means.
But of course I cannot do this because using this syntax I can't assign a macro with a macro unless I do something more. Not sure what it is though...
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.