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

Dear All,

 

I need to execute a linux command and from de result create a data set:

 

%macro psawk;
%sysexec %str(ps aux | awk '{print $1,$2,$3,$6,$11}' >/SASData/test11.txt);
%mend psawk;
%psawk;

 

from this I get a file with the following structure

 

sas.png

 

Regards,

Abraham

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

Assign filename to the file created by the command and read it into sas:

 

filename result '/SASData/test11.txt';  

data want;
    infile result truncover firstobs=2;
    input user $ @; 
    if user = "USER" then do; input; return; end; /* skip 1st line */
    input  pid cpu rss command $;
run;
    

View solution in original post

7 REPLIES 7
Cynthia_sas
Diamond | Level 26
Hi:
In order to turn this file into a SAS data set, you will have to import it into SAS. You can do this a variety of ways -- either PROC IMPORT or a DATA step program. I would probably use a DATA step program.

What code did you try? What do you want the variables to be named. Note that SAS Variable names should start with a letter or underscore, so %CPU is not a SAS variable name.

cynthia

cynthia
kaoru013
Fluorite | Level 6

thanks for all your help

Shmuel
Garnet | Level 18

Assign filename to the file created by the command and read it into sas:

 

filename result '/SASData/test11.txt';  

data want;
    infile result truncover firstobs=2;
    input user $ @; 
    if user = "USER" then do; input; return; end; /* skip 1st line */
    input  pid cpu rss command $;
run;
    
kaoru013
Fluorite | Level 6

Thanks for your answer, it it works but I have a problem in the command column just put a fragment and not the complete information, this field can have up to 400 characters.

 

Regards

Cynthia_sas
Diamond | Level 26
Hi:
Then you need to have a Length statement:
LENGTH command $400;

Cynthia
Shmuel
Garnet | Level 18

The default length is 8.

Change the $ after command to $400.  (include the dot).

Tom
Super User Tom
Super User

Why create the text file at all?

data want;
    infile "ps aux | awk '{print $1,$2,$3,$6,$11}'" pipe firstobs=2 truncover ;
    input user :$40. pid cpu rss command $500.;
run;

 

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

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 7 replies
  • 3606 views
  • 3 likes
  • 4 in conversation