BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
woo
Barite | Level 11 woo
Barite | Level 11

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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Pass an empty input and see what you get.

 

length record $300.;
input ;
record = _infile_;

View solution in original post

6 REPLIES 6
ballardw
Super User

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.

Reeza
Super User

Make sure you first have X command enabled, otherwise pipe command are not allowed.

woo
Barite | Level 11 woo
Barite | Level 11

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

 

Reeza
Super User

Pass an empty input and see what you get.

 

length record $300.;
input ;
record = _infile_;
woo
Barite | Level 11 woo
Barite | Level 11

Thanks Reeza, it worked fine,,,

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 3170 views
  • 3 likes
  • 4 in conversation