BookmarkSubscribeRSS Feed
woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

Hello friends, i am using below code to get ALL files + file size + changed (date and time) from specific dir. however, not getting enough data as output - only getting file names. I need file size and changed variable as well...

 

have

name                                             size                                 changed

sfvjsddvjlsbvaskdv                                                               11/8/2016 10:10:00 AM

sjklvnsvnsvk                                                                         11/8/2016  5:15:20 AM 

svjnksdivjpifvusvknivuhiv          123456                               11/7/2016 15:07:00 PM

 

code    

filename init pipe "dir /test/";

data all_files;

length fname $ 200 size $ 20 time $ 20;

infile init truncover;

input fname size time$;

run;

 

output

sfvjsddvjlsbvaskdv                                                              

sjklvnsvnsvk                                                                        

svjnksdivjpifvusvknivuhiv

 

want

name                                             size                                 changed

sfvjsddvjlsbvaskdv                                                               11/8/2016 10:10:00 AM

sjklvnsvnsvk                                                                         11/8/2016  5:15:20 AM 

svjnksdivjpifvusvknivuhiv          123456                               11/7/2016 15:07:00 PM

16 REPLIES 16
Kurt_Bremser
Super User

If your system is Windows, then doing dir /temp is a bad idea, because the forward slash signals a commandline option to dir, so it will complain because emp (what follows after the /t, which is valid) is invalid.

Use dir c:\temp\ instead.

If you're working on UNIX (Linux), use ls -l instead of dir.

 

What does your log say?

RW9
Diamond | Level 26 RW9
Diamond | Level 26

For windows:

filename tmp pipe 'dir "S:\temp\rob" /tc /a-d';

data want;
  infile tmp dlm="¬";
  length buff $2000;
  input buff;
  if _n_ > 3 and index(buff,"File")=0 and index(buff,"Dir")=0 then do;
    date=input(scan(buff,1," "),ddmmyy10.);
    size=...;
    name=...;
  end;
  format date date9.;
run;

Only parsed out creation date indicated by /tc, you can add the other two in, quite simple.

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

Thank you RW9 - we have Linux - and my ultimate goal is finding unused/orphaned temporary sessions and delete it...

 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Then you would need to manipulate the code to match the OS commands you would use on Linux.

 

As for removing temporary sessions, how would looking at a dir list show you unused sessions?  I would imagine there are better processes out there to do this, however without knowing software/setups etc. I can't really say.  Check with your SAS admin, software support to see on options.

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

thank you "" ,

 

i tried below and worked fine.

 

    

data test;

length access $ 20 files $ 200;

infile "cd /testdir; ls -lt;" pipe firstobs=2;

input access nx $ user $ group $ size $ month $ day $ time $ files;

run;

 

however, i have day and month are character - and i want to combine in one variable like month_day with appropriate format...what can i do? i tried different way but didn't work...

 

i can simply combine it like,

month_day=month||day; but want proper format....

          

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

@RW - i am planning to prepare spcific variable with x command value for all temp dir like;@RW - i am planning to prepare spcific variable with x command value for all temp dir like;

 

spec_var

x "rm dir sas_work........"

x" rm dir sas_util......."

 

and then use filevar to execute to delete it...would that work?

 

Appreciate your input...

ballardw
Super User

You might investigate the SAS external file functions Dopen to "open" a directory for reading, Dnum the number of items in a directory, Dread returns names of directory members, Doptnum and Doptname information items availalbe in a directory, Finfo information abut a file using Foptnum and Foptname gets things like the creation date, file size and such, And Fdelete to remove files or directories.

 

Unless you are frequently changing operating systems once you know the optnames or optnums you want code isn't terribly long and you need not creat filereferences or use the X command. Or you could build the the X commands and execute using Call Execute.

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

somehow, cleanwork utility doens't do all cleanup. still some session left behind...some of them are really old sessions....dont' know why...

ChrisNZ
Tourmaline | Level 20

Have you seen this?

you'll need to replace the commands (with ls and ps) and then this macro may be useful to you.

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

what macro?

Kurt_Bremser
Super User

cleanwork willl remove directories that have no corresponding process (the process number is hexadecimally coded into the directory name) in the process list. So your problem might not be orphaned data, but orphaned processes. These need to be dealt with by killing them.

Oh yes, and for killing processes and removing data of other users, you need superuser privileges in UNIX.

 

PS cleanwork works fine here, but my SAS runs not on a Windows toybox, but on an operating system that deserves such a label.

woo
Lapis Lazuli | Level 10 woo
Lapis Lazuli | Level 10

thank you all for your thoughts.

 

i am still wonder if we have any script or program already written to take care of it for incstance says - sas eg temp session which has active PID and if that session is staying there from long time - how to delete it without any manual process like with script or program.

 

so i was trying to list all sas_work...or sas_util... directores and try to delete it with OS cmd (by sas program - by making rm dir cmd and executing it with filevar) - if anything is in use - won't delete and if something has left b/h - it would cleared it...

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!

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
  • 16 replies
  • 7775 views
  • 0 likes
  • 6 in conversation