Desktop productivity for business analysts and programmers

linux command from sas eg

Accepted Solution Solved
Reply
Super Contributor
Super Contributor
Posts: 404
Accepted Solution

linux command from sas eg

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;

 

 


Accepted Solutions
Solution
‎11-16-2017 05:47 PM
Super User
Posts: 22,850

Re: linux command from sas eg

Pass an empty input and see what you get.

 

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

View solution in original post


All Replies
Super User
Posts: 13,063

Re: linux command from sas eg

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.

Super User
Posts: 22,850

Re: linux command from sas eg

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

Super Contributor
Super Contributor
Posts: 404

Re: linux command from sas eg

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

 

Solution
‎11-16-2017 05:47 PM
Super User
Posts: 22,850

Re: linux command from sas eg

Pass an empty input and see what you get.

 

length record $300.;
input ;
record = _infile_;
Super Contributor
Super Contributor
Posts: 404

Re: linux command from sas eg

Thanks Reeza, it worked fine,,,

 

Super User
Posts: 9,593

Re: linux command from sas eg

Try the option

dlm='09'x

in the infile statement. UNIX utilities usually separate column output by tabs.

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
☑ This topic is solved.

Need further help from the community? Please ask a new question.

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