DATA Step, Macro, Functions and more

CRDATE for a CSV file?

Accepted Solution Solved
Reply
Contributor alr
Contributor
Posts: 39
Accepted Solution

CRDATE for a CSV file?

  Hi,
Is it possible to get creation date (crdate) and/or last modified date of a CSV file with SAS before import of the file?


data mydata;
infile 'C:\MyData\thedata.csv' dlm='3B'x;
   input var1 :$7.
            var2 :8.
            ;
run;

Also, creation date of the file thedata.csv.


Accepted Solutions
Solution
‎01-02-2015 11:25 AM
PROC Star
Posts: 7,487

All Replies
Super User
Posts: 11,343

Re: CRDATE for a CSV file?

Yes.

Look at the functions, and online help examples for functions FINFO, FOPTNUM, FOPTNAME and related. You can get the system information available from your operating system.

Regular Contributor
Posts: 180

Re: CRDATE for a CSV file?

Assuming the operating system is Windows, the following program creates the macrovariable CRDATE with the date and time the file was last modified. You can later use this value in any SAS data or proc step:

%let folder=C:\MyData;

%let csvfile=THEDATA.CSV;

filename folder pipe "dir &folder";

data _null_;

   infile folder lrecl=256 pad;

   length file $32 date $10 time $5 ampm $2;

   input;

   file=scan(_infile_,5,' ');

   if upcase(trim(file))="&csvfile" then do;

      date=scan(_infile_,1,' ');

      time=scan(_infile_,2,' ');

      ampm=scan(_infile_,3,' ');

      datenum=input(date,mmddyy10.);

      timenum=input(time,time5.);

      if ampm='PM' then timenum=timenum+(12*3600);

      dtnum=dhms(datenum,hour(timenum),minute(timenum),second(timenum));

      call symputx('CRDATE',put(dtnum,datetime19.));

      stop;

   end;

run;

%put &crdate;

CTorres

Solution
‎01-02-2015 11:25 AM
PROC Star
Posts: 7,487

Re: CRDATE for a CSV file?

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 558 views
  • 11 likes
  • 4 in conversation