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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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