12-30-2015 02:35 PM
I have a shell script, within that I execute SAS code. Now I would like to pass a value of macro variable to linux environment.
I am using Korn shell, running sas program in batch mode.
I tried to use following code in SAS, to pass value fo Macrovariable to linux.
X 'export Lvalue=&tbl_cnt '; and
X 'export Lvalue="&tbl_cnt" ';
This one does not work.?
how can solve this problem.
12-30-2015 03:04 PM
It would be nice if there were a %SYSPUT function, sort of the opposite of %SYSGET. But if your illustrated code is the right syntax for the EXPORT command, you would need to get rid of the single quotes to allow your macro variable reference to resolve. An easy way (not guaranteed but definitely worth a try) would be to switch from X to %SYSEXEC:
%SYSEXEC export LValue=&tbl_cnt;
If you need quotes around &TBL_CNT, use double quotes, not single quotes.
12-30-2015 07:21 PM - edited 12-30-2015 07:35 PM
Besides of the single quotes which won't allow the SAS macro variable to resolve I believe the main issue is:
- The KSH is the parent, the SAS program is the child.
- The EXPORT command sets a UNIX variable to "global"; but global in this context is not the same than in SAS. EXPORT makes variables set in the parent available to its children - but EXPORT doesn't make variables from the children available to its parents.
I'm not a UNIX expert so here just some options you could try and see if they work.
A: Define the UNIX variables in your KSH parent shell script as global using EXPORT. Then populate the variables within SAS. (I'm not sure though how far environment separation goes. The variables as such will exist in the child process with the value set by the parent. I'm not sure if a value altered by the child will be available to the parent though).
B: In the SAS child process write to a file, something like ~/myvars.ksh, which creates the UNIX variables with values as you need them. Then include this file in your parent script for execution after the call to the SAS process.
C: There might also be an option using a PIPE but I would have to do some own research to come up with more than just stating that this is something which is eventually possible.
D: I'm not sure if this is possible but if you could call the SAS process ".../sas.sh -..." as included script using the dot syntax instead of a separate process then the ksh script and the SAS process would share the environment.
Syntax would be:
. <path>/sas.sh -sysin <sasprog.sas>
12-31-2015 02:27 AM
12-31-2015 10:01 AM
I had to do in different way as export didn't work. I used call system('touch /user/file.new'). In ksh, instead of value of variable I am checking the existence of the file.new file. thank you all
01-01-2016 05:39 PM
I believe you've chosen the easiest approach to get what you need (which is a good thing). It's a variation of my option B.
Make sure that you delete the token file after you've checked for its existence as else in the next run...
Also: If the same user could execute your program multiple times in paralell you will need some timestamp and/or PID as part of your token file name.