BookmarkSubscribeRSS Feed
SASHunter
Obsidian | Level 7
This is my problem: The kornshell will be running two SAS programs, the first will create a value that is stored in a variable. The second SAS program needs this value to process other things.

So is there a way to pass a SAS variable that was created in one SAS program back to the UNIX shell so that the next SAS program can use it?

Thanks
6 REPLIES 6
Cynthia_sas
SAS Super FREQ
Hi:
You might want to take a look at the documentation on using UNIX. It includes this section on environment variables:
http://support.sas.com/documentation/cdl/en/hostunx/61879/HTML/default/defenv.htm

cynthia
SASHunter
Obsidian | Level 7
We know how to get the variables from UNIX to the SAS program by way of the EXPORT command. What I'm asking is how to update a UNIX variable from within SAS.

Thanks so much.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You can set UNIX environment variables from SAS, or you can use an external (sequential) file method to share "data" between independent SAS programs and/or other applications or OS functions.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument on your topic for consideration:

set unix environment variable site:sas.com
SASHunter
Obsidian | Level 7
Here is an example of what we are trying to do:

******** shell
#! /usr/bin/ksh
set -o allexport

export set z=0
print $z
sas sum.sas

print $z

set +o allexport



********** sum.sas

data _null_;
call system ('export set z=3');
run;

----------------------------------------------------------------

From within SAS we want to set an environment variable (Z) to 3 and print from shell.
But it is coming back with zero not three.


Thanks for your continued help!
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
If the SAS execution behavior is not as documented/expected, suggest you contact SAS tech support for further assistance. Useful DOC references specific to the SAS UNIX companion guide are provided below.

Scott Barry
SBBWorks, Inc.

SAS Companion for UNIX Environments, Executing Operating System Commands from Your SAS Session
http://support.sas.com/documentation/cdl/en/hostunx/61879/HTML/default/xcomm.htm

SAS Companion for UNIX Environments, , CALL SYSTEM Routine: UNIX
http://support.sas.com/documentation/cdl/en/hostunx/61879/HTML/default/callsys.htm
data_null__
Jade | Level 19
I don't know the correct terminology but I think the problem is that when you run a SAS program it spawns another environment that inherits all the variables from the original. I can create new variables and modify existing variables but I have been unable to have an effect on the original environment.

If the program that modifies or creates the environment variables starts the second program using SYSTASK perhaps then the variables created by program 1 are available.

My shell is tcsh

program 1.
[pre]
x setenv TESTENV hello;

systask command "/usr/local/bin/sas testenv02.sas";
[/pre]

Log from program 2.
[pre]
1
2
3 %put NOTE: %SYSGET(TESTENV);
NOTE: hello
[/pre]

So, as was suggest is might be easier to communicate between programs with objects that you have complete control over, SAS data sets are good.

I expect there is a way to get the environment variables to work and I look forward to learning the solution.

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 6 replies
  • 4041 views
  • 0 likes
  • 4 in conversation