I have a sas program named test.sas having a macro:
%macro mymacro(input1=, input2=, input3=);
/*
piece of code.
*/
%mymacro(input1=a, input2=b, input3=c)
I want to supply these macro input parameters as runtime parameters on unix server.
something like :
sas test.sas parameter1 parameter2 parameter3.
How will I call this program by passing input and get these inputs in my macro.
Please suggest a way.
@Arjumand wrote:
Hi Kurt,
Can I get parameters in macro call:
%test(
a= %sysget(PARAM1)
,b= %sysget(PARAM2)
,c= %sysget(PARAM3)
,d= %sysget(PARAM4)
,e= %sysget(PARAM5)
);
Of course you can!
Based on your example (please use a code posting window - {i} or "little running man" in the future for posting code, to preserve formatting) I wrote a short program and saved it as envtest.sas:
%macro test(a=,b=,c=,d=,e=);
%put a=&a;
%put b=&b;
%put c=&c;
%put d=&d;
%put e=&e;
%mend;
%test(
a= %sysget(PARAM1)
,b= %sysget(PARAM2)
,c= %sysget(PARAM3)
,d= %sysget(PARAM4)
,e= %sysget(PARAM5)
);
Then I wrote this shell script:
export PARAM1=xxx export PARAM2=yyy export PARAM3=zzz export PARAM4=111 export PARAM5=222 sas envtest.sas
After running the shell script, this is the log:
1 %macro test(a=,b=,c=,d=,e=); 2 %put a=&a; 3 %put b=&b; 4 %put c=&c; 5 %put d=&d; 6 %put e=&e; 7 %mend; 8 9 %test( 10 a= %sysget(PARAM1) 11 ,b= %sysget(PARAM2) 12 ,c= %sysget(PARAM3) 13 ,d= %sysget(PARAM4) 14 ,e= %sysget(PARAM5) 15 ); a=xxx b=yyy c=zzz d=111 e=222 NOTE: SAS Institute Inc., SAS Campus Drive, Cary, NC USA 27513-2414 NOTE: Das SAS System used: real time 0.28 seconds cpu time 0.02 seconds
You need to wrap your macro in a .sas file and use the -SYSPARM option to pass the parameters http://support.sas.com/documentation/cdl/en/hostwin/69955/HTML/default/viewer.htm#n0u0t8c3b3syeen1l1...
There's a corresponding SYSPARM() function http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/viewer.htm#n1ug7uhp2d4... which will retrieve the parameters in one string which you can then split up with the SCAN() function.
Use a shell script that sets environment variables before running the program:
export PARAM1=xxx export PARAM2=yyyy export PARAM3=zzz sas test.sas
And then retrieve the environment variables in your SAS code
%let param1=%sysget(PARAM1);
%let param2=%sysget(PARAM2);
%let param3=%sysget(PARAM3);
@Arjumand wrote:
Hi Kurt,
Can I get parameters in macro call:
%test(
a= %sysget(PARAM1)
,b= %sysget(PARAM2)
,c= %sysget(PARAM3)
,d= %sysget(PARAM4)
,e= %sysget(PARAM5)
);
Of course you can!
Based on your example (please use a code posting window - {i} or "little running man" in the future for posting code, to preserve formatting) I wrote a short program and saved it as envtest.sas:
%macro test(a=,b=,c=,d=,e=);
%put a=&a;
%put b=&b;
%put c=&c;
%put d=&d;
%put e=&e;
%mend;
%test(
a= %sysget(PARAM1)
,b= %sysget(PARAM2)
,c= %sysget(PARAM3)
,d= %sysget(PARAM4)
,e= %sysget(PARAM5)
);
Then I wrote this shell script:
export PARAM1=xxx export PARAM2=yyy export PARAM3=zzz export PARAM4=111 export PARAM5=222 sas envtest.sas
After running the shell script, this is the log:
1 %macro test(a=,b=,c=,d=,e=); 2 %put a=&a; 3 %put b=&b; 4 %put c=&c; 5 %put d=&d; 6 %put e=&e; 7 %mend; 8 9 %test( 10 a= %sysget(PARAM1) 11 ,b= %sysget(PARAM2) 12 ,c= %sysget(PARAM3) 13 ,d= %sysget(PARAM4) 14 ,e= %sysget(PARAM5) 15 ); a=xxx b=yyy c=zzz d=111 e=222 NOTE: SAS Institute Inc., SAS Campus Drive, Cary, NC USA 27513-2414 NOTE: Das SAS System used: real time 0.28 seconds cpu time 0.02 seconds
To set environment variables in Windows from the commandline, use the set command.
My method would be to write a simple .bat file that looks quite similar to the UNIX shell script, with set instead of export.
Others may prefer to use VBS, as that is more "modern".
Since I don't run SAS on Windows, the question does not arise for me. I have a real operating system at hand.
Yes. You can do it .@Rick_SAS has written a blog about it before. Check out.
http://blogs.sas.com/content/iml/2015/03/16/pass-params-sysget.html
Your sas is under UNIX/LINUX/AIX OS? If it was,then Kurt's answer is right for you. otherwise, I don' know what is going on with it.
calling @Rick_SAS
see my paper Sysparm Companion
code is on this page: sco Parse sysparm
Ron Fehd command-line options maven
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.