BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Arjumand
Calcite | Level 5

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

@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

View solution in original post

13 REPLIES 13
ChrisBrooks
Ammonite | Level 13

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...

Arjumand
Calcite | Level 5
ok.. How will I retrieve the parameters in macro @ChrisBrooks
ChrisBrooks
Ammonite | Level 13

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.

Kurt_Bremser
Super User

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
Calcite | Level 5
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)
);
Kurt_Bremser
Super User

@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
Arjumand
Calcite | Level 5
@Kurt_Bremser: Just one last question, how can we call the same program from command promt in windows?
Thanks so much for your help 🙂
Kurt_Bremser
Super User

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.

Ksharp
Super User

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

Arjumand
Calcite | Level 5
Thanks a lot everyone.
Arjumand
Calcite | Level 5
Hi @Ksharp,

I am running as per you suggested and the program seems to be executing, but the parameters are not read using the command in this blog. Plus I am getting "-set is not recognized as an internal or external command" error in console. Please suggest.
Ksharp
Super User

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

Ron_MacroMaven
Lapis Lazuli | Level 10

see my paper Sysparm Companion

 

code is on this page: sco Parse sysparm

 

Ron Fehd  command-line options maven

 

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
  • 13 replies
  • 3592 views
  • 2 likes
  • 5 in conversation