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

Hi,

 

I have requirement to create Archive of Older Files and the Current folder has SAS/log/lst/rtf/pdf/png files created with Datetime Stamp.

Now,I need to move all the files from the current folder to the Archive and just retain only the recent TimeStamped Set of files in Current.

I am planning to route all SAS Created Files to Current folder and in the same code writing the below Piece of Macro to move the previously created files.

 

%macro test;

%sysexec %str(mkdir ./Archive;mv ./Current/* ./Archive);

%mend test;

%test;

 

problem Area:

But after "/*" ,SAS Code is getting commented..

So,I am not able to select all the files from the Current Folder.

Can you please help me out to fix this approach?

 

Thanks in advance!

 

Regards,

Abi

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Use the filename pipe method, and put the command in quotes:

filename oscmd "mkdir ./Archive;mv ./Current/* ./Archive 2>&1";

data _null_;
infile oscmd;
input;
put _infile_;
run;

You won't have a problem with seeming SAS syntax (eg comments) inside the command string, and all responses from the system will end up in the SAS log.

View solution in original post

5 REPLIES 5
Reeza
Super User
Instead of %STR() try using quotation marks which will mask the asterisk (*) which is causing the issue.

Abinaya
Calcite | Level 5

That's Great!

 

Thanks much Reeza..I can copy individual file..

But I am not able to copy all the files using below macro..Can you please help??

%let path=/sdsbai/common/SAS_new/Final_Testing;

%macro test;

%sysexec "mv &path/Test_case1/* &path/Archive";

%mend test;

%test;

 

Thanks!

Abi

 

 

Reeza
Super User
mv is a system command that moves files from one directory to another, guessing Unix/Linux. %SYSEXEC passes the command to the operating system to execute.

So you need to find the correct unix command, but that's not a question I can answer - I google unix commands every time I need them :).
Kurt_Bremser
Super User

Use the filename pipe method, and put the command in quotes:

filename oscmd "mkdir ./Archive;mv ./Current/* ./Archive 2>&1";

data _null_;
infile oscmd;
input;
put _infile_;
run;

You won't have a problem with seeming SAS syntax (eg comments) inside the command string, and all responses from the system will end up in the SAS log.

Abinaya
Calcite | Level 5

Thanks all!!

Much appreciated Solutions 🙂

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 5 replies
  • 11355 views
  • 1 like
  • 3 in conversation