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 🙂
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: