DATA Step, Macro, Functions and more

Moving files after output is successfully generated

Reply
Occasional Contributor
Posts: 14

Moving files after output is successfully generated

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
N/A
Posts: 0

Re: Moving files after output is successfully generated

what operating system are you using?
Super Contributor
Super Contributor
Posts: 3,174

Re: Moving files after output is successfully generated

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.
Super Contributor
Super Contributor
Posts: 3,174

Re: Moving files after output is successfully generated

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.
Occasional Contributor
Posts: 14

Re: Moving files after output is successfully generated

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
Super Contributor
Super Contributor
Posts: 3,174

Re: Moving files after output is successfully generated

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
Super Contributor
Super Contributor
Posts: 3,174

Re: Moving files after output is successfully generated

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.
Occasional Contributor
Posts: 14

Re: Moving files after output is successfully generated

I'm using UNIX AIX 5.3 platform.
Occasional Contributor
Posts: 14

Re: Moving files after output is successfully generated

Thanks Scott.
This works out.

Regards,
Radhika
Ask a Question
Discussion stats
  • 8 replies
  • 323 views
  • 0 likes
  • 3 in conversation