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
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?
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.
Thank you RW9 - we have Linux - and my ultimate goal is finding unused/orphaned temporary sessions and delete it...
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.
thank you "KurtBremser" ,
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....
@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...
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.
To remove the orphaned work locations from crashed SAS sessions, use the cleanwork utility provided by SAS.
somehow, cleanwork utility doens't do all cleanup. still some session left behind...some of them are really old sessions....dont' know why...
Have you seen this?
you'll need to replace the commands (with ls and ps) and then this macro may be useful to you.
what macro?
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.
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...
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.