Help using Base SAS procedures

Passing SAS variables to the UNIX kornshell

Reply
Frequent Contributor
Posts: 82

Passing SAS variables to the UNIX kornshell

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
SAS Super FREQ
Posts: 8,868

Re: Passing SAS variables to the UNIX kornshell

Posted in reply to SASHunter
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
Frequent Contributor
Posts: 82

Re: Passing SAS variables to the UNIX kornshell

Posted in reply to SASHunter
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.
Super Contributor
Super Contributor
Posts: 3,174

Re: Passing SAS variables to the UNIX kornshell

Posted in reply to SASHunter
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
Frequent Contributor
Posts: 82

Re: Passing SAS variables to the UNIX kornshell

Posted in reply to SASHunter
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!
Super Contributor
Super Contributor
Posts: 3,174

Re: Passing SAS variables to the UNIX kornshell

Posted in reply to SASHunter
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
Respected Advisor
Posts: 3,799

Re: Passing SAS variables to the UNIX kornshell

Posted in reply to SASHunter
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.
Ask a Question
Discussion stats
  • 6 replies
  • 2465 views
  • 0 likes
  • 4 in conversation