BookmarkSubscribeRSS Feed
asma2017
Calcite | Level 5

Hi everyone, I want to transfer a macro variable into an environnement variable unix 

 

I have a sh script  that execute a code sas, the code sas contains a macro variable called toto eqaul to 0 , What I want is that By running the sh script in unix the value of the macro variable &toto is displayed. this is the code that i used but it's not working for me 

 

the code sas 

%let toto = 0; 
X 'export Lvalue= &toto';

the script sh : end pre load is displayed but Lvalue is empty

#!/bin/bash

/sas/sasbin/SASFoundation/9.4/sas -sysin /sasdata/04_code_sas/test.sas  -NOPRINT -nosyntaxcheck -noerrabend -log /sasdata/07_logs/test.log

echo $Lvalue
echo end pre load check
4 REPLIES 4
kiranv_
Rhodochrosite | Level 12

can you use double quotes instead of single.

 

please look into this post something similar

 

https://communities.sas.com/t5/Base-SAS-Programming/Getting-a-macro-variable-to-resolve-within-an-x-...

 

asma2017
Calcite | Level 5

 

it's not working 

%let tbl = 0;

%SYSEXEC "export Lvalue= &tbl";

This is what I got by running the sh script this time

 

/bin/bash: export Lvalue= 0 : commande introuvable
./sasdata/03_script_sh/test.sh: ligne5: $'\r' : commande introuvable
./sasdata/03_script_sh/test.sh: ligne7: $'\r' : commande introuvable

end pre load check
kiranv_
Rhodochrosite | Level 12

Sas macrovariable is always resolves as a  character, that might be an issue.

Patrick
Opal | Level 21

@asma2017

SAS executes as a child process of the calling shell. The child process gets an environment copy of the calling shell and you can export environment variables from parent to child. 

The parent environment is sheltered against any changes from the child (things run in separate environments) and you can principally not alter the parent environment and though you can't set an environment variable in the child environment which becomes available to the parent.

 

You can pass a value back to the parent by writing it to an external file in the child and then read the file with the parent. 

You can also set up a pipe to exchange the values (needs some shell scripting which you can Google).

 

And as a side note:

Instead of using the sas binary under /../SASFoundation/9.4/sas I'd recommend to use sas.sh which you should find under a path similar to /.../Config/Lev1/SASApp/sas.sh

Using sas.sh has the advantage that your SAS environment will get invoked with all the configuration settings as you get them when using SAS EG or SAS Studio.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 4 replies
  • 1700 views
  • 1 like
  • 3 in conversation