DATA Step, Macro, Functions and more

getting relevant information for filepaths

Reply
Occasional Contributor
Posts: 9

getting relevant information for filepaths

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

 

Super User
Posts: 22,874

Re: getting relevant information for filepaths

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

 


 

SAS Employee
Posts: 13

Re: getting relevant information for filepaths

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.

 

Occasional Contributor
Posts: 9

Re: getting relevant information for filepaths

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?.

Super User
Posts: 22,874

Re: getting relevant information for filepaths

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

 

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

Occasional Contributor
Posts: 9

Re: getting relevant information for filepaths

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

Occasional Contributor
Posts: 9

Re: getting relevant information for filepaths

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

Occasional Contributor
Posts: 9

Re: getting relevant information for filepaths

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. 

SAS Employee
Posts: 13

Re: getting relevant information for filepaths

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.  Smiley Happy  You really don't want me to provide the answer do you?

Occasional Contributor
Posts: 9

Re: getting relevant information for filepaths

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

Ask a Question
Discussion stats
  • 9 replies
  • 98 views
  • 3 likes
  • 3 in conversation