SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Kirito1
Quartz | Level 8
I want to get last modified date of a file in my folder using SAS how can I do that? Any help is appreciated.
1 ACCEPTED SOLUTION
7 REPLIES 7
LinusH
Tourmaline | Level 20

A number of ways.

Completely in SAS you can use a combination of SAS external file functions:

https://documentation.sas.com/doc/en/imlcdc/14.2/imlug/imlug_langref_sect561.htm

Or you can use X command/filename pipe to execute a dir/ls command to retrieve that information.

Data never sleeps
Kirito1
Quartz | Level 8

I read it all but unable to use it, Although what I found using google says the physical file does not exist but its there in my network folder. And I am able to import that same file using proc import

The below is my code:

%let filepath = /SAS_library/NAS_CA/QR/QR/Import_file/MERMAST_INFILE.csv;

data _null_;
lastmod = attrn("&filepath.", "LM");
put "Last Modified Date: " lastmod datetime.;
run;

Please suggest what I should Do. Is there any solution for this.

ballardw
Super User

Is the file in question a SAS data set, other SAS file or something external to SAS such as a text file read for data?

Kirito1
Quartz | Level 8

Its not a SAS data set its an external CSV file in my network folder. 

Just to be clear I am able to import that CSV file using proc import. The task here for me is to check if the dumped file has last modified date of today then I want to schedule that job.

Kirito1
Quartz | Level 8
Thank You very much Yes it solve my problem.
yabwon
Onyx | Level 15

How about using BasePlus package and the dirsAndFiles macro

%dirsAndFiles(
  </path/to/your/directory>
  ,ODS=work.outputDataSet
  ,keepDirs=0 /* ignore directories */
  ,details=1 /* get details */
  ,maxDepth=1 /* don't look in subdirectories */
)

And then use "LastModified" variable.

 

All the best

Bart

 

P.S. To install and use basePlus package do: 

  • Enable the framework [first time only]: 
  • filename SPFinit url "https://raw.githubusercontent.com/yabwon/SAS_PACKAGES/main/SPF/SPFinit.sas";
    %include SPFinit; /* enable the framework */
  • Install the framework and the package on your machine in the folder you created:
  • filename packages "</your/directory/for/packages/>"; 
    %installPackage(SPFinit basePlus) 
  • From now on, in your SAS session just run it like this (you can put those 3 lines in autoexec): 
  • filename packages "</your/directory/for/packages/>";
    %include packages(SPFinit.sas);
    
    %loadPackage(basePlus)  

Link to details.

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 3952 views
  • 4 likes
  • 5 in conversation