BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kmoonmurr
Fluorite | Level 6

 

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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?

View solution in original post

5 REPLIES 5
Reeza
Super User

Look up the SYSLAST automatic macro variable.

 

After your data set add a line:

 

%let infile = &syslast.;

kmoonmurr
Fluorite | Level 6
This is a great tip and works - Thanks!
Astounding
PROC Star

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?

kmoonmurr
Fluorite | Level 6
Thank you, it works!
Reeza
Super User

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...

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1609 views
  • 4 likes
  • 3 in conversation