DATA Step, Macro, Functions and more

Command for Pulling value from UNIX at runtime

Reply
Occasional Contributor
Posts: 9

Command for Pulling value from UNIX at runtime

Hi all,

I am using Base SAS and running codes in UNIX environment.

I am aware of X command, %SYSEXEC by which we can do some unix operations inside SAS.

ex:

X rm "./test.txt"; (to delete file test.txt)

Now I need to get in a value from runtime. Is there any command to get Value into SAS.

This will help me a lot as I can get values at run time.

I can write a shell script to get value and pass it to SAS but want to know if I can do it from inside code.

Thanks,

Karthik

Super User
Posts: 5,424

Re: Command for Pulling value from UNIX at runtime

Try to be more specific on how and what kind of values you want to pass to SAS.

Since SAS can read almost anything, there are tons of ways to pass/import values into SAS.

One way you might be interested in, is to import OS environment variable values - check out sysget.

Data never sleeps
Super Contributor
Posts: 474

Re: Command for Pulling value from UNIX at runtime

Yes, %SYSGET will retrieve UNIX environment variables, and it may be all you need.

Another feature is the SYSPARM macro variable which is specified when launching SAS from the command line (-sysparm "value", option).

More on this here:

http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000543608.htm

If what you need is access to the output of a system command (ls, cat, etc) submited within SAS then take a peak on pipe file commands:

http://support.sas.com/documentation/cdl/en/hostunx/63053/HTML/default/n1ceb0xedanuj3n19l3g73awk1wf....

Cheers from Portugal!

Daniel Santos @ www.cgd.pt

Frequent Contributor
Posts: 125

Re: Command for Pulling value from UNIX at runtime

Posted in reply to DanielSantos

Wow, I did not know about the Filename-Feature for system commands.

Looks great. Thanks for sharing!

Frequent Contributor
Posts: 125

Re: Command for Pulling value from UNIX at runtime

One - not so elegant - approach would be to write the output of your command into a file and then read this file in a Data-Step.

Like so:

x df -k | awk '{print $4}' > /somefolder/somefile.txt;

DATA work.data;

     INFILE '/somefolder/somefile.txt' [...]

RUN;

Which would create data with all the free space in kbyte (in this example just the free space, not the folders or mount-points for which the free space was analysed. It does not make much sense like this, but then again it is just an example.)

Hope this helps.

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