BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Cugel
Obsidian | Level 7
I want to create a variable that I can then use in any where statement. Something like this
DATA CREATE_JOB_SPECIFIC_VARS;
%let year_filter_1 = 2019;
%let year_filter_2 = extract(year from sysdate)-5;
RUN;
The intention is to create the variable in a "sql execute" or "user written" statement.
When I create the variable as mentioned in the example, the variable seems to have no content over time.
TEST_JOB EXAMPLE.JPG
1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

You do not need that data step around the macro statements; macro code is resolved before any other code is handed off to the data step compiler or any procedures.

This creates and shows your macro variables:

%let year_filter_1 = 2019;
%let year_filter_2 = %eval(%sysfunc(year(%sysfunc(today())))-5);
%put &=year_filter_1;
%put &=year_filter_2;

Log:

 73         %let year_filter_1 = 2019;
 74         %let year_filter_2 = %eval(%sysfunc(year(%sysfunc(today())))-5);
 75         %put &=year_filter_1;
 YEAR_FILTER_1=2019
 76         %put &=year_filter_2;
 YEAR_FILTER_2=2016

 

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

You do not need that data step around the macro statements; macro code is resolved before any other code is handed off to the data step compiler or any procedures.

This creates and shows your macro variables:

%let year_filter_1 = 2019;
%let year_filter_2 = %eval(%sysfunc(year(%sysfunc(today())))-5);
%put &=year_filter_1;
%put &=year_filter_2;

Log:

 73         %let year_filter_1 = 2019;
 74         %let year_filter_2 = %eval(%sysfunc(year(%sysfunc(today())))-5);
 75         %put &=year_filter_1;
 YEAR_FILTER_1=2019
 76         %put &=year_filter_2;
 YEAR_FILTER_2=2016

 

Cugel
Obsidian | Level 7
Hi Kurt, Thanks for your help.
I am a SAS novice and it is not entirely clear to me where I can best include the code lines in the job. In the "sql execute" or in the "user written" statement.
Or somewhere else in the job ?. I am not yet very familiar with the structure of SAS macros.




Cugel
Obsidian | Level 7
I have included Kurt's solution in "SQL execute" transformation. 
In the job, this transformation is performed first. This solution works.
However, if the job crashes, the variable is no longer available and the first step must be performed again.
SAS DIS execute.PNG
Tom
Super User Tom
Super User

What tool are you using to build that work flow?  Is it Enterprise Guide?  SAS/Studio? Something else?

Cugel
Obsidian | Level 7
Hi Tom



Thanks for your help, we are using SAS Data Integration Studio 4.903.


SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 911 views
  • 0 likes
  • 3 in conversation