BookmarkSubscribeRSS Feed
Kirito1
Quartz | Level 8

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

3 REPLIES 3
brzcol
SAS Employee

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
Quartz | Level 8
Thank you for your response @brzcol can you Please explain what does the code above is doing as I am unable to understand how can I inculcate the above code with my existing code.
ballardw
Super User

@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.

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 3 replies
  • 662 views
  • 1 like
  • 3 in conversation