BookmarkSubscribeRSS Feed
tej123
Fluorite | Level 6

Hi here is how my input file ( it can have thousands records) looks like

 

input file:

name 

/home/tej/a.sas7bdat

/home/bn/b.sas7bdat

/hom/df.sas7bdat

 

Outputfile:

 name                                  user            date

/home/tej/a.sas7bdat          x                   ...

 /home/bn/b.sas7bdat         y                  ....

/hom/df.sas7bdat               z                     ....

 

 

In a nutshell i should run 'ls -ul ' command on each record of the input file and append its output to the record.  My way or most obvious way of doing this create intermediate data for each record and finally append everything.  Is there any other smart way of doing where we can avoid creating intermediate data set for each record. 

 

Thanks

 

9 REPLIES 9
Reeza
Super User

If you ran LS on the folders wouldn't it have all that information?

Other than the user, which I wouldn't necessarily trust, the other information is available from the Dictionary tables.

 


@tej123 wrote:

Hi here is how my input file ( it can have thousands records) looks like

 

input file:

name 

/home/tej/a.sas7bdat

/home/bn/b.sas7bdat

/hom/df.sas7bdat

 

Outputfile:

 name                                  user            date

/home/tej/a.sas7bdat          x                   ...

 /home/bn/b.sas7bdat         y                  ....

/hom/df.sas7bdat               z                     ....

 

 

In a nutshell i should run 'ls -ul ' command on each record of the input file and append its output to the record.  My way or most obvious way of doing this create intermediate data for each record and finally append everything.  Is there any other smart way of doing where we can avoid creating intermediate data set for each record. 

 

Thanks

 


 

JerryV
SAS Employee

A couple of different options.

1) Before going into SAS, run your ls -l command (1>myNewInput.txt) for all input rows.  Then input myNewInput.txt

2) if xcmd is available in your SAS Session.  (EG usually is not).  Use the FILENAME statement with the PIPE engine and the 'ls -l' command for all of your datarows.

3.) Use a combination of the foptname and finfo functions on each of your input rows.

 

tej123
Fluorite | Level 6

something along this lines:

 

%macro path(val);

 

%global userid;

filename inf pipe "ls -ul &val" lrecl=200;

 

data _null_;

length user $8;

input user;

call symputx('user',user);

run;

%mend path;

 

data input file;

set inputfile;

call execute( '%path('||filename||')');

run;

the above methodology is failing. i dont know why?.

Reeza
Super User

the above methodology is failing. i dont know why?.

 

How is it failing? What does 'failing' mean?

tej123
Fluorite | Level 6

Sorry, when i meant fail, in the call execute command the filepath value "/apps / ... "  is not getting passed.

tej123
Fluorite | Level 6

Sorry, when i meant fail, in the call execute command the filepath value  is not getting passed.

tej123
Fluorite | Level 6

I am so sorry for the confusion. the call execute command works and the code is working.  I had 3 different sas programs opened and got confused myself as to which variables i am using. 

JerryV
SAS Employee

You're on the right track.  You're missing: 

infile inf;

before your input statement.

You will also have some data arranging to do once you call execute your %path macro.  Like where and how are you going to store user, date, filename ....

 

Keep going.  🙂  You really don't want me to provide the answer do you?

tej123
Fluorite | Level 6

Haha, thank you. The code is working after adding the infile.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 9 replies
  • 960 views
  • 3 likes
  • 3 in conversation