BookmarkSubscribeRSS Feed
KarthikR
Calcite | Level 5

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

4 REPLIES 4
LinusH
Tourmaline | Level 20

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
DanielSantos
Barite | Level 11

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

mfab
Quartz | Level 8

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

Looks great. Thanks for sharing!

mfab
Quartz | Level 8

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.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 2960 views
  • 1 like
  • 4 in conversation