Good day,
I would like to add a date to a file, however, it should reflect the previous month. Reason is the files for December will be received and ran in January, however, the file name should then have DEC2016 in it.
My code works, however, it gives an output of JAN1960 (which is day 0).
I cannot seem to find what the issue is. My code below:
PROC EXPORT DATA = V_B OUTFILE = "&path\V_B_%sysfunc(putn(%eval(%sysfunc(month(-1))),monyy7)).csv" dbms= csv replace; RUN;
Thank you
Hi.
This will sort it for you I think.
* create macro var with desired date, migth be helpful ahead;
%let FDATE=%sysfunc(putn(%sysfunc(intnx(MONTH,%sysfunc(date()),-1)),monyy7.));
PROC EXPORT DATA = V_B
OUTFILE = "&path\V_B_&FDATE..csv" dbms= csv replace; RUN;
You need do use the DATE function to retrieve the filesystems date and the INTNX function to subtract one month from it.
More on DATE: http://support.sas.com/documentation/cdl/en/etsug/63939/HTML/default/viewer.htm#etsug_intervals_sect...
More on INTNX: https://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p10v3sa3i4...
Hope it helps.
Daniel Santos @ www.cgd.pt
Hi.
This will sort it for you I think.
* create macro var with desired date, migth be helpful ahead;
%let FDATE=%sysfunc(putn(%sysfunc(intnx(MONTH,%sysfunc(date()),-1)),monyy7.));
PROC EXPORT DATA = V_B
OUTFILE = "&path\V_B_&FDATE..csv" dbms= csv replace; RUN;
You need do use the DATE function to retrieve the filesystems date and the INTNX function to subtract one month from it.
More on DATE: http://support.sas.com/documentation/cdl/en/etsug/63939/HTML/default/viewer.htm#etsug_intervals_sect...
More on INTNX: https://support.sas.com/documentation/cdl/en/lefunctionsref/63354/HTML/default/viewer.htm#p10v3sa3i4...
Hope it helps.
Daniel Santos @ www.cgd.pt
The following should work:
"&path\V_B_%sysfunc(intnx(month,%sysfunc(today()),-1,b),monyy7.).csv"
You get a date of 1960 because function month(-1) doesn't work the way you believe it does (look it up in the manual) and returns a value of 12 - which SAS interpretes as the 12th day when the count of days starts - which is 1/1/1960.
Thank you. Both solutions work.
I'm still fairly new at sas, so thank you for helping me 🙂
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.