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!
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 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.
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;
Thank you so much. This worked for me.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.