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

Hi,

use the intnx function in a macro variable:

 

%let start   = %sysfunc(intnx(MONTH,%sysfunc(today()),-1,SAME),DDMMYYS10.);

 

It, works...but I would like to know if is there another way to do the same operation?

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

You can use my data step in that main program.

I guess you will %include that in all your programs or autoexec's. Data steps in %include'd files will work just as if they were written directly in the calling program.

View solution in original post

7 REPLIES 7
Kurt_Bremser
Super User

My preferrred method is to use a data _null_ step and call symput:

data _null_;
start = intnx('MONTH',today(),-1,'SAME');
call symput('start',put(start,DDMMYYS10.));
run;

So all the calculations are done in pure data step language and easier to read, because you don't have to care for all the %sysfunc's.

Rakeon
Quartz | Level 8

Thanks,

but I need to use it outside the data step, because I write the main program.

 

 

 

 

Kurt_Bremser
Super User

My data _null_ step delivers eactly the same result that your %let does.

Keep this in mind:

if you write a %let in a data step, it will not be executed in the data step (!!!). Instead it will be executed upon the fetching of the code, so logically it is the same as if you wrote it immediately before the data step.

 

BTW, what do you mean by "main program"?

Rakeon
Quartz | Level 8

Yes,

thank for you answer and for your help,

for me,

the main Program is a file where I put all important macro variable and the libname for the path of several programs *.sas

 

 

 

 

Kurt_Bremser
Super User

You can use my data step in that main program.

I guess you will %include that in all your programs or autoexec's. Data steps in %include'd files will work just as if they were written directly in the calling program.

Rakeon
Quartz | Level 8

Ah,

ok thanks!!

Kurt_Bremser
Super User

To further elaborate:

%include is a macro (pre-processor) statement. As soon as it is encountered, the included file is read and placed in the input buffer of the SAS interpreter in place of the %include statement. So you can use any SAS code in a file that is to be %include'd.

It's just that, after the include is performed, the resulting code needs to be syntactically correct and make sense.

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
  • 7 replies
  • 4341 views
  • 1 like
  • 2 in conversation