Desktop productivity for business analysts and programmers

Create an envionnement variable unix from a macro variable sas

Reply
New Contributor
Posts: 2

Create an envionnement variable unix from a macro variable sas

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
Regular Contributor
Posts: 230

Re: Create an envionnement variable unix from a macro variable sas

[ Edited ]

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

 

New Contributor
Posts: 2

Re: Create an envionnement variable unix from a macro variable sas

 

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
Regular Contributor
Posts: 230

Re: Create an envionnement variable unix from a macro variable sas

[ Edited ]

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

Respected Advisor
Posts: 3,837

Re: Create an envionnement variable unix from a macro variable sas

[ Edited ]

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

 

Ask a Question
Discussion stats
  • 4 replies
  • 141 views
  • 1 like
  • 3 in conversation