SAS copy files from directory

Reply
Contributor
Posts: 37

SAS copy files from directory

Hi ,

I have 100' of files in my directory  of which i need to use the file with the latest date .

 

For example if i have two files with same names but different dates at the end  I should pick up latest file and copy in x location or directory . But if there is only one file like this HPG-XX-YYYY_Pricing C_X_03_19_2012_1.xls . then use this and copy in x location or directory

 

HPG-XX-YYYY_Pricing A_X_03_19_2011_1.xls

HPG-XX-YYYY_Pricing A_X_03_19_2012_1.xls

 

 

HPG-XX-YYYY_Pricing B_X_03_19_2011_1.xls

HPG-XX-YYYY_Pricing B_X_03_19_2012_1.xls

 

HPG-XX-YYYY_Pricing C_X_03_19_2012_1.xls

 

Can anyone pls help . Can we approach this using a macro or any other sas procedure

 

Thanks

Super User
Posts: 19,850

Re: SAS copy files from directory

If you search on here you'll find many examples. 

 

The general steps are get a listing of files from the directory into a dataset. Process as necessary, in your case chose latest. Then copy. 

 

That being said, this is probably better done as a UNIX or powershell script that you can then call from SAS. 

 

So, before we can point you to reference, what's your OS, and can you execute X commands from SAS?

Contributor
Posts: 37

Re: SAS copy files from directory

Hi

 

I should  check because when i run  below code in my sas eg

data _null_;
call system ('ls -l');
run;

 

i am getting below  error it means i dont have access ?

ERROR: Shell escape is not valid in this SAS session.

 

Contributor
Posts: 37

Re: SAS copy files from directory

HI Reeza ,

 

Can u let me know the unix script to be executed in sas to achieve the task if poosible . ?

 

 

 

 

Thanks

Super User
Posts: 5,434

Re: SAS copy files from directory

The word "unix" is supposed to point you to a UNIX forum. This is not a SAS specific question.
Data never sleeps
Contributor
Posts: 37

Re: SAS copy files from directory

Sure .

 

Thanks

Ask a Question
Discussion stats
  • 5 replies
  • 296 views
  • 0 likes
  • 3 in conversation