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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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