/** Macro technique **/ %macro FileAttribs(filename); %local rc fid fidc; %local Bytes CreateDT ModifyDT; %let rc=%sysfunc(filename(onefile,&filename)); %let fid=%sysfunc(fopen(&onefile)); %let Bytes=%sysfunc(finfo(&fid,File Size (bytes))); %let CreateDT=%qsysfunc(finfo(&fid,Create Time)); %let ModifyDT=%qsysfunc(finfo(&fid,Last Modified)); %let fidc=%sysfunc(fclose(&fid)); %let rc=%sysfunc(filename(onefile)); %put NOTE: File size of &filename is &Bytes bytes; %put NOTE- Created &CreateDT; %put NOTE- Last modified &ModifyDT; %mend FileAttribs; /** Just pass in the path and file name **/ %FileAttribs(c:\aaa.txt)
Hello, I am using this macro to get the &ModifyDT. I would like to know what is the format of this macro?
Can how can we convert it to get only the datepart and from there to get only the month.
Regards,
Alain
You need to convert the text string containing the modify date to a SAS date/time value, you do this via the INPUTN function, and then you can find the month and date. And it probably would be easier in a DATA step, but here it is in the macro
%macro FileAttribs(filename);
%local rc fid fidc;
%local Bytes CreateDT ModifyDT;
%let rc=%sysfunc(filename(onefile,&filename));
%let fid=%sysfunc(fopen(&onefile));
%let Bytes=%sysfunc(finfo(&fid,File Size (bytes)));
%let CreateDT=%qsysfunc(finfo(&fid,Create Time));
%let ModifyDT=%qsysfunc(finfo(&fid,Last Modified));
%let fidc=%sysfunc(fclose(&fid));
%let rc=%sysfunc(filename(onefile));
%put NOTE: File size of &filename is &Bytes bytes;
%put NOTE- Created &CreateDT;
%put NOTE- Last modified &ModifyDT;
%let modifydt1= %sysfunc(inputn(&modifyDT,anydtdtm.));
%put MONTH= %sysfunc(month(%sysfunc(datepart(&modifydt1))));
%put DATE= %sysfunc(putn(%sysfunc(datepart(&modifydt1)),date9.));
%mend FileAttribs;
You haven't shown any of the values so we have no idea.
The way the value appears is probably dependent on the operating system the SAS server is using. Windows and Unix might present that information different.
You could try using the ANYDTDTE informat to convert it to a date.
%let date=%sysfunc(inputn(&ModifyDT,anydtdte24.));
That should give a value like 22181 which is how SAS stores the date 2020-09-23.
If you want the value formatted for human consumption instead add a format to the %SYSFUNC() call. You could even use the MONTH or MONNAME format to get the month number or name.
%let month=%sysfunc(inputn(&ModifyDT,anydtdte24.),month2.);
You need to convert the text string containing the modify date to a SAS date/time value, you do this via the INPUTN function, and then you can find the month and date. And it probably would be easier in a DATA step, but here it is in the macro
%macro FileAttribs(filename);
%local rc fid fidc;
%local Bytes CreateDT ModifyDT;
%let rc=%sysfunc(filename(onefile,&filename));
%let fid=%sysfunc(fopen(&onefile));
%let Bytes=%sysfunc(finfo(&fid,File Size (bytes)));
%let CreateDT=%qsysfunc(finfo(&fid,Create Time));
%let ModifyDT=%qsysfunc(finfo(&fid,Last Modified));
%let fidc=%sysfunc(fclose(&fid));
%let rc=%sysfunc(filename(onefile));
%put NOTE: File size of &filename is &Bytes bytes;
%put NOTE- Created &CreateDT;
%put NOTE- Last modified &ModifyDT;
%let modifydt1= %sysfunc(inputn(&modifyDT,anydtdtm.));
%put MONTH= %sysfunc(month(%sysfunc(datepart(&modifydt1))));
%put DATE= %sysfunc(putn(%sysfunc(datepart(&modifydt1)),date9.));
%mend FileAttribs;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.