BookmarkSubscribeRSS Feed
rsb7678
Calcite | Level 5
HI,

Please let me know if there is an alternative simpler way of moving the all the files n folders to another folder.

Below is my SAS code:

DATA _NULL_;
call symput("path","/pgm/intel");
call symput("roll_ind", "Y");
run;

%put "PATH: " &path.;
%put "Roll indicator: " &roll_ind.;

DATA _NULL_;
if "&roll_ind." = "Y" then do;
/* delete the prev folder */
call system ("rm -r &path./prev") ;

/* move the last weeks data to previous */
call system ("mv &path./curr &path./prev") ;

/* move this weeks data to current */
call system ("mv &path./r_out &path./curr") ;
call system ("mv &path./csampl/output &path./curr/csampl") ;
call system ("mv &path./pipe &path./curr") ;

/* Setting the appropriate permissions to the files in current */
call system ("cd &path./curr") ;
call system ("chmod -R 755 *.sas7bdat");
call system ("chmod -R 755 *.gz");
call system ("chmod -R 755 *.zip");

/* Creating the directories for the processing the data next week */
*** ***;
call system ("mkdir &path./r_out") ;
call system ("cd &path./r_out") ;
call system ("chmod -R 755 ");

call system ("mkdir &path./r_out/process1") ;
call system ("cd &path./r_out/process1") ;
call system ("chmod -R 755 ");

call system ("mkdir &path./r_out/process1/Temp") ;
call system ("cd &path./r_out/process1/Temp") ;
call system ("chmod -R 755 ");

*** ***;
call system ("mkdir &path./csampl") ;
call system ("cd &path./csampl") ;
call system ("chmod -R 755 ");

*** ***;
call system ("mkdir &path./pipe") ;
call system ("cd &path./pipe") ;
call system ("chmod -R 755 ");

put "******************************************************************************";
put "MESSAGE: Data is ROLLED into current and previous folders";
put "******************************************************************************";

end;
else do;
put "******************************************************************************";
put "MESSAGE: Data is NOT Rolled into current and previous folders";
put "******************************************************************************";
end;
RUN;


Thanks
RB
8 REPLIES 8
deleted_user
Not applicable
what operating system are you using?
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
SAS provides DATA step functions, which also can be invoked using %SYSFUNC from macro language. I believe you would have better success and can interrogate / respond to specific environment conditions (likely regardless of OS) if you use this approach. Search the SAS support http://support.sas.com/ website for SAS-hosted documentation (including "companion" documentation for various OS environments) and also supplemental technical / conference papers on this type of topic.

Scott Barry
SBBWorks, Inc.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
At a minimum, consider reducing the amount of SAS code, by converting your series of CALL EXECUTE commands to a DATA step with a DO / END loop, and having DATALINES; coded with your series of commands imbedded instream ; read up the input with an INPUT statement in your DATA step. And to substitute your "variable information", use a special character string like $mydir$ which you would reference in a SAS assignment statement, as shown below:

%let _mydir_ = /yada/yada/yada;
DATA _NULL_;
INFILE DATALINES TRUNCOVER;
LENGTH COMMAND $200;
INPUT COMMAND $CHAR200. ;
COMMAND = TRANWRD(COMMAND,'_mydir_',"&_mydir_");
* UNCOMMENT LINE BELOW WHEN READY TO GO. ;
* CALL SYSTEM(COMMAND);
PUTLOG '>ECHO_COMMAND> ' COMMAND;
DATALINES;
rm _mydir_
mkdir _mydir_
...whatever other commands needed...
RUN;


Scott Barry
SBBWorks, Inc.
rsb7678
Calcite | Level 5
Hi Scott,
A quick question , why are you using tranwrd function and the macro variable _mydir_ ?
Each step is a different command with a different directory path.

Thanks
RB
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Sounds like a static macro variable (substitution) approach will not work - the TRANWRD function translates the word (sorry, could not help myself!) found in "argument2" to the word found in "argument3".

Scott Barry
SBBWorks, Inc.

SAS 9.2 DOC reference - TRANWRD Function:
http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000215027.htm
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
So, instead of a macro variable, use instream data-strings with your explicit commands to invoke - it's easier than all that CALL SYSTEM('"); logic, I'd say.

There are other techniques but this one is straightforward and easily supported.

Scott Barry
SBBWorks, Inc.
rsb7678
Calcite | Level 5
I'm using UNIX AIX 5.3 platform.
rsb7678
Calcite | Level 5
Thanks Scott.
This works out.

Regards,
Radhika

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 8 replies
  • 1150 views
  • 0 likes
  • 3 in conversation