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

Hi,

I am using proc append to add data from the previous month's dataset to a current months dataset.

 

Run 1—Last month—Dataset A -- ‘’Dataset_092019’’

 

Run 2- This month- Dataset B –‘’dataset_102019’’

 

Append- 2  to 1 i.e.  the current month's dataset 102019 to  Dataset 092019  

 

The issue that I am having is --> End of this year December 2019 -run 1; Run 2- Jan 2020. 

 

I used the macro below for the naming convention. 

 

%let mnth=%sysfunc(intnx(day,%sysfunc(today()),0,B),month.);


%let yr=%sysfunc(intnx(day,%sysfunc(today()),0,B),year.);
%put &mnth&yr;

 

I think it wont work for the year transition.. Any advice? 

 

Also I am automating this. So it should work for all the years going forward, not just 2019 and 2020. 

 

Thanks! 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Here is one way to get a macro variable with the previous month value in MMYYYY appearance.

I use a data step because the number of nestings of %sysfunc needed create ugly code and some difficulty keep () straight.

 

data _null_;
   call symputx('lastmyr',put( (intnx('month',today(),-1,'b')),mmyyn6.));
run;
%put &lastmyr;

And you could get the current month the same in the same data step just change the -1 to 0

 

data _null_; 
call symputx('lastmyr',put( (intnx('month',today(),-1,'b')),mmyyn6.)); 
call symputx('thismyr',put( (intnx('month',today(), 0,'b')),mmyyn6.)); 

run; 


%put &lastmyr  &thismyr;

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

@ilearnsas wrote:

 

 

I think it wont work for the year transition. Any advice? 

 


Why doesn't it work? Explain in detail. Show us the full code rather than a few lines.

--
Paige Miller
ballardw
Super User

Here is one way to get a macro variable with the previous month value in MMYYYY appearance.

I use a data step because the number of nestings of %sysfunc needed create ugly code and some difficulty keep () straight.

 

data _null_;
   call symputx('lastmyr',put( (intnx('month',today(),-1,'b')),mmyyn6.));
run;
%put &lastmyr;

And you could get the current month the same in the same data step just change the -1 to 0

 

data _null_; 
call symputx('lastmyr',put( (intnx('month',today(),-1,'b')),mmyyn6.)); 
call symputx('thismyr',put( (intnx('month',today(), 0,'b')),mmyyn6.)); 

run; 


%put &lastmyr  &thismyr;
ilearnsas
Obsidian | Level 7

Thank you so much. This worked for me. 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 3 replies
  • 695 views
  • 1 like
  • 3 in conversation