BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
alr
Quartz | Level 8 alr
Quartz | Level 8

  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.

1 ACCEPTED SOLUTION
3 REPLIES 3
ballardw
Super User

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.

CTorres
Quartz | Level 8

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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