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

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
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

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
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

Thanks Reeza, it worked fine,,,

 

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 6 replies
  • 1993 views
  • 3 likes
  • 4 in conversation