First I was trying to give the filename the exact date on which I exported the file.
proc export data=AVG
outfile="xyz/Transactions \%sysfunc( today(), date9 ).csv"
REPLACE
DBMS=CSV;
run;
This is giving me an output filename as (Transactions 22DEC2022).
--------------
But now I want the date which I specify in a code should be attached with the File name.
For Example: I specified a date in code as 19DEC2022 and the file name is Transactions. So, the output filename should be Transactions 19DEC2022.
I think this problem could be solved using macros but I am not sure how to proceed it. Please! help.
SAS dates are counts of days, starting with 1960-01-01 as day zero.
So you only need to subtract a day from today:
%let yesterday = %sysfunc(putn(%sysfunc(today())-1,yymmddn8.));
Or you use a DATA step:
data _null_;
call symputx("yesterday",put(today()-1,yymmddn8.));
run;
From longtime IT experience, two tips:
How do you "specify a date in a code"? Please show that particular piece of code.
Use the "little running man" button to open a window into which you paste the code. This keeps formatting, leaves the code as is (no HTML formatting), and provides coloring similar to the SAS Enhanced Editor.
To store today's date in a macro variable, do
%let today = %sysfunc(today(),yymmddn8.);
If you want to use the date in code (for calculations or comparisons), omit the format in %SYSFUNC.
SAS dates are counts of days, starting with 1960-01-01 as day zero.
So you only need to subtract a day from today:
%let yesterday = %sysfunc(putn(%sysfunc(today())-1,yymmddn8.));
Or you use a DATA step:
data _null_;
call symputx("yesterday",put(today()-1,yymmddn8.));
run;
From where do you get the date? Is it calculated in code, read from a dataset, or supplied in another way to your code?
Either you have a way to automatically calculate the date, or you need to write it literally into the code anyway.
I have already shown how to store a calculated date into a macro variable.
yesterday is a macro variable, not a data step function.
outfile="xyz/Transactions \&yesterday..csv"
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.