SASUnit Examples  Version 1.5.0
linux/_xcmd.sas
Go to the documentation of this file.
1 
21 %MACRO _xcmd(i_cmd);
22  %LOCAL logfile l_cmd rc filrf;
23 
24  %LET logfile=%sysfunc(pathname(work))/___log.txt;
25  %let rc = %_delfile(&logfile);
26  %sysexec &i_cmd > "&logfile";
27 
28  %IF &g_verbose. %THEN %DO;
29  %PUT ======== OS Command Start ========;
30  /* Evaluate sysexec´s return code*/
31  %IF &sysrc. = 0 %then %put &g_note.(SASUNIT): Sysrc : 0 -> SYSEXEC SUCCESSFUL;
32  %ELSE %PUT &g_error.(SASUNIT): Sysrc : &sysrc -> An Error occured;
33 
34  /* put sysexec command to log*/
35  %PUT &g_note.(SASUNIT): SYSEXEC COMMAND IS: &i_cmd > "&logfile";
36 
37  /* write &logfile to the log */
38  /* for the following commands "cd", "pwd", "setenv" or "umask" SAS executes
39  SAS equivalent of these commands -> no files are generated that could be read */
40  %LET filrf=_tmpf;
41  %LET rc=%sysfunc(filename(filrf,&logfile));
42  %LET rc = %sysfunc(fexist(&filrf));
43 
44  %IF (&rc) %THEN %DO;
45  DATA _NULL_;
46  infile "&logfile" truncover;
47  input;
48  putlog _infile_;
49  RUN;
50  %END;
51  %ELSE %PUT No File Redirection for Commands cd, pwd, setenv and umask;
52  %LET rc=%sysfunc(filename(filrf));
53 
54  %PUT ======== OS Command End ========;
55  %END;
56 %MEND _xcmd;
57