DATA Step, Macro, Functions and more

Macro issues in Call system

Reply
Contributor
Posts: 29

Macro issues in Call system


Dear All,

I wanna excute following command in UNIX envornment.

data _null_;

call system (' cd /prod/user/home/gyb420/check/bck; ksh check.ksh  abc1  abc2 ');

run;

the ksh script will run and passing parameter1 abc1 and parameter2 abc2 to the shell script.

Now,  I wanna use macro variables to replace values abc1, abc2.  So I tried

%let value1=abc1; %let value2=abc2;

data _null_;

call system (" cd /prod/user/home/gyb420/check/bck; ksh check.ksh  &value1  &value2 ");

run;

but the process failed to run;

Then I also tried:

data _null_;

call system (" cd /prod/user/home/gyb420/check/bck; ksh check.ksh   SYMGET('value1')   symget('value2')  ");

run;

Still no luck. Thanks in advance for any suggestions to resolve this macro variables in Call System.

Lei

Trusted Advisor
Posts: 3,212

Re: Macro issues in Call system

Please debug your code showing all values going to those vars and the returning ones.
There are a lot of other ways to do x-cmd but all have the challenge to pass correct strings to the OS.  
The symget approach is incorrect syntax in the way your coded that. It will try to do that in Unix.

---->-- ja karman --<-----
Contributor
Posts: 29

Re: Macro issues in Call system

Hi Karman. I know there are X or %SYSEXEC MACRO or pipe commands I can use. But I prefer to use call system here because UNIX commands can be run conditionally if desired in data step using SAS syntax.


Super User
Posts: 10,020

Re: Macro issues in Call system

%let value1=abc1; %let value2=abc2;

options symbolgen ; *<--- to see if the macro variable have been resolved;

data _null_;

call system (" cd /prod/user/home/gyb420/check/bck ");

call system ("   ksh check.ksh  &value1  &value2 ") ;

call system ("   ./check.ksh  &value1  &value2  ") ;

run;

Contributor
Posts: 29

Re: Macro issues in Call system

Hi Ksharp,

Here is the log file for running the sas code on UNIX sasgsub -gridwait -gridsubmitpgm check.sas . it calls the check.ksh and passing 2 parameters abc1 and abc2 . then create a text file with correct message.

  data _null_;

     call system (" cd /prod/user/home/gyb420/check/bck; ksh check.ksh abc1 abc2 ");

   run;

NOTE: PROCEDURE PRINTTO used (Total process time):
      real time           0.04 seconds
      user cpu time       0.00 seconds
      system cpu time     0.00 seconds
      memory              1166.56k
      OS Memory           6692.00k
      Timestamp           05/18/2014 11:57:40 AM
      Page Faults                       0
      Page Reclaims                     442
      Page Swaps                        0
      Voluntary Context Switches        22
      Involuntary Context Switches      0
      Block Input Operations            0
      Block Output Operations           0
   

6        !                                       
7         
8          data _null_;
9          call system (" cd /prod/user/home/gyb420/check/bck; ksh check.ksh abc1 abc2 ");
10         run;

NOTE: DATA statement used (Total process time):
      real time           0.05 seconds
      user cpu time       0.01 seconds
      system cpu time     0.01 seconds
      memory              435.15k
      OS Memory           6692.00k
      Timestamp           05/18/2014 11:57:40 AM
      Page Faults                       0
      Page Reclaims                     423
      Page Swaps                        0
      Voluntary Context Switches        33
      Involuntary Context Switches      0
      Block Input Operations            0
3                                                          The SAS System                                 11:57 Sunday, May 18, 2014

      Block Output Operations           0
   

Ksh script below:

#!/usr/bin/ksh 

echo " sel max($2) (title '') from $1 where $2 >date-5 ">/prod/user/home/gyb420/check/bck/test.txt

and desired test.txt file will be created with message below:

sel max(abc2) (title '')  from abc1 where abc2 >date-5

Contributor
Posts: 29

Re: Macro issues in Call system

Now , I wanna achieve the same results but with 2 macro variables table_nm and dt . After I add single quote around macro variables,  the issues got resolved and desired file generated sucessfully.  Thanks a lot for your sugguestion.

NOTE: PROCEDURE OPTIONS used (Total process time):
      real time           0.00 seconds
      user cpu time       0.00 seconds
      system cpu time     0.00 seconds
      memory              44.93k
      OS Memory           5156.00k
      Timestamp           05/18/2014 12:09:55 PM
      Page Faults                       0
      Page Reclaims                     21
      Page Swaps                        0
      Voluntary Context Switches        0
2                                                          The SAS System                                 12:09 Sunday, May 18, 2014

      Involuntary Context Switches      0
      Block Input Operations            0
      Block Output Operations           0


39        +/*    This is a user defined autoexec file for         */
40        +/*    SAS Enterprise Guide users.                      */
41        +/*                                                     */
42        +/*    Place user defined autoexec options here         */
43        +/*                                                     */
44        +
NOTE: %INCLUDE (level 2) ending.
NOTE: %INCLUDE (level 1) resuming.

NOTE: AUTOEXEC processing completed.

1
2          options symbolgen mlogic mprint;
3          %let table_nm=abc1;
4          %let dt=abc2;
5
6
7          data _null_;
8          call system (" cd /prod/user/home/gyb420/check/bck ");
9          call system (" ksh check.ksh '&table_nm' '&dt' ");
SYMBOLGEN:  Macro variable TABLE_NM resolves to abc1
SYMBOLGEN:  Macro variable DT resolves to abc2
10         %put &table_nm ;
SYMBOLGEN:  Macro variable TABLE_NM resolves to abc1

11         %put &dt;
SYMBOLGEN:  Macro variable DT resolves to abc2

12         run;

NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      user cpu time       0.00 seconds
      system cpu time     0.00 seconds
      memory              440.03k
      OS Memory           5668.00k
      Timestamp           05/18/2014 12:09:55 PM
      Page Faults                       0
      Page Reclaims                     434
      Page Swaps                        0
      Voluntary Context Switches        33
      Involuntary Context Switches      0
      Block Input Operations            0
      Block Output Operations           0


NOTE: SAS Institute Inc., SAS Campus Drive, Cary, NC USA 27513-2414
NOTE: The SAS System used:
      real time           0.27 seconds
      user cpu time       0.02 seconds
      system cpu time     0.04 seconds
      memory              4709.75k
      OS Memory           5672.00k
3                                                          The SAS System                                 12:09 Sunday, May 18, 2014

      Timestamp           05/18/2014 12:09:55 PM
      Page Faults                       0
      Page Reclaims                     8536
      Page Swaps                        0
      Voluntary Context Switches        1131
      Involuntary Context Switches      25
      Block Input Operations            8
      Block Output Operations           112

Trusted Advisor
Posts: 3,212

Re: Macro issues in Call system

Ok jay that is clear choice.
I would have it more liked when you would say:  the string manipulation in a data-step can be better controlled.
The most clear approach then is first building a string in datastep variable and use that in the "call system" function call.
The debugging will be easier as you can put the value of that string also into your log. 
Do not forget to declare that string long enough.

The disadvantage of the "call system" is that you cannot debug easilly the script execution catching those normal (fileid=1) and error messages (fileid=2) unless you code that in the scripting.   

IN your last run you missed to add to set the options as KSharp suggested. There is still no debugging info.

---->-- ja karman --<-----
Contributor
Posts: 29

Re: Macro issues in Call system

Hi Karman,

Thanks a lot for your inputs. For sas grid , can I add -sysparm option after sasgsub -gridwait -gridsubmitpgm check.sas ?
I received an error message below when I submit sasgsub -gridwait -gridsubmitpgm check.sas -sysparm 'abc'

error: an unknown command line option sysparm was specified.

I know it works in non-grid environment. Could it be different syntax in sas grid?

Thanks  !

Trusted Advisor
Posts: 3,212

Re: Macro issues in Call system

Ok jay the sasgsub call question.

It is submitting code to the Grid environment mostly there is LSF behind. The gridwait and gridsubmitpgm are not normal known as sas options.

Grid Computing in SAS(R) 9.4, Second Edition (SASGSUB Overview)

As you are submitting jobs to LSF the sas scritp syntax is encapsulated at some point. The sasgridopts parameter looks to be that encapsulation.
Grid Computing in SAS(R) 9.4, Second Edition   (SASGSUB Syntax: Submitting a SAS Program in Batch Mode)
As your LSF environment is having his own security you could need a user/password for that.

---->-- ja karman --<-----
Ask a Question
Discussion stats
  • 8 replies
  • 941 views
  • 3 likes
  • 3 in conversation