hello, I have sas 9.4 on linux and trying to run some linux command to get specific list of files,
if run this command "du -hs * | sort -hr | head -3" in linux it give me output like,
200G filename_1
100G filename_2
50G filename_3
trying to get this in sas datasets using below statement but not giving what I want, any suggestion?
data test;
length file_size $20 file_name $ 200;
infile "cd /home/userid; du -hs * | sort -hr | head -3;" pipe;
input file_size $ file_name $;
run;
Pass an empty input and see what you get.
length record $300.;
input ;
record = _infile_;
Please describe how it is "not giving what I want".
If you get errors or no output post the code and the log into a code box using the forum {I} menu icon.
If you get unexpected values then show what you did get.
Since you did not specify an actual length for the file_size and file_name variables they likely defaulted to 8 characters and truncated some of your file_name values.
Make sure you first have X command enabled, otherwise pipe command are not allowed.
no error
x cmd is enabled
may be length issue
log looks like,
28 data test;
29 length file_size $20 file_name $ 200;
30 infile "cd /home/userid; du -hs * | sort -hr | head -3;" pipe;
31 input file_size $ file_name $;
32 run;
NOTE: The infile "cd /home/userid; du -hs * | sort -hr | head -3;" is:
Pipe command="cd /home/userid; du -hs * | sort -hr | head -3;"
NOTE: LOST CARD.
file_size=516K XYZ_work1B7B000 file_name= _ERROR_=1 _N_=364
NOTE: 365 records were read from the infile "cd /home/userid; du -hs * | sort -hr | head -3;".
The minimum record length was 56.
The maximum record length was 99.
NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
NOTE: The data set WORK.TEST has 363 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 1.10 seconds
cpu time 0.01 seconds
Pass an empty input and see what you get.
length record $300.;
input ;
record = _infile_;
Thanks Reeza, it worked fine,,,
Try the option
dlm='09'x
in the infile statement. UNIX utilities usually separate column output by tabs.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.