05-19-2017 09:45 AM
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
05-19-2017 09:52 AM - edited 05-19-2017 09:54 AM
can you use double quotes instead of single.
please look into this post something similar
05-19-2017 10:13 AM
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
05-19-2017 07:58 PM - edited 05-19-2017 08:04 PM
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.