0

I am running a shell script via X command within a SAS macro. I want to use a macro variable defined in SAS macro, in my shell script. I know if I pass that macro variable as parameter to shell script, I can resolve that within X command.

For example, the following will work fine, I know:

%macro a;

%let var1=test;

X "abc.sh &var1";

%mend;
%a;

with this shell script:

echo "value is $1" >  myfile.txt

What I want:

%macro a;

%let var1=test;

X "abc.sh";

%mend;

%a;

with this shell script:

echo "value is &val1" >  myfile.txt

Is there any way to resolve macro variable in shell script? I did my research but couldn't find anything.

1 Answer 1

0

The shell is not going to be able to resolve a variable from an external macro system, such as &val1, like you suggest in your example.

You can have the shell use values from the environment. For instance, if you export a variable VAR1 with contents test, then you could use this in abc.sh:

echo "value is $VAR1" >myfile.txt

(I'm only using all uppercase as that's the usual convention for exported variables in the shell, using a lowercase $var1 would be fine, as long as the name you export is also lowercase.)

How to export a variable from SAS is something you'll need to figure out (I have no experience with SAS.) It seems that SAS supports a setenv statement or command. setenv is typically used by some shells to export variables, so that's where I'd look if I was trying to export a variable myself.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .