I was working on SAS and I was able to get todays date with the file name and number of records with it. Unfortunately, the user wants last modified date to be attached with filename.
Kindly, help I have no Idea how to proceed. Although, I was reading and found the below link
https://support.sas.com/kb/40/934.html
I think the link might help. If someone could provide a solution.
Thanks in advance
Hello,
Do you just want the date included or you want both the date and time?
Here is a possible solution to get you started based on the link you provided. There may be better alternatives. What this creates is an excel file called Tester_28Feb2023.
Is that what you were looking for?
%let exportpath=A:\examplefolder\output\Tester.xlsx;
filename fileref "&exportpath";
data a(drop=fid);
infile fileref truncover obs=1;
fid=fopen('fileref');
moddate=scan(finfo(fid,'Last Modified'),1,':'); /*Just give the date portion instead of full date time*/
call symputx('ModDate',Moddate); /*Create a macro variable called ModDate that holds the value of the variable created above*/
run;
%put &ModDate; /*Make sure it looks right*/
proc export data=sashelp.class dbms=xlsx outfile="A:\examplefolder\output\Tester_&ModDate..xlsx" replace;
run;
@Kirito1 wrote:
I was working on SAS and I was able to get todays date with the file name and number of records with it. Unfortunately, the user wants last modified date to be attached with filename.
Kindly, help I have no Idea how to proceed. Although, I was reading and found the below link
https://support.sas.com/kb/40/934.html
I think the link might help. If someone could provide a solution.
Thanks in advance
Last modified for the file created? Or for the SAS data set?
If the SAS data set you can consult the SAS metadata. This is just one way. The Dictionary.Tables special view contains the names, types and some of the characteristics, such as number of observations, creation date and modification date. The Libname and Memname (date set name) are stored in upper case letters. The SQL INTO allows selecting the values into macro variables as about the shortest code.
data work.newjunk; x=3; run; proc sql noprint; select strip(put(nobs,best12. -L)), put(datepart(modate),date9.) into: Numobs , : Moddate from dictionary.tables where libname='WORK' and memname='NEWJUNK' ; quit; %put number of obs is: &Numobs., Modification Date is: &Moddate. ;
Use the &numobs and &Moddate in your file name.
Still think you should use the YYMMDDN8. format instead of Date9. though.
Nearly 200 sessions are now available on demand in the Innovate Hub.
Watch Now →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.