Hi, suppose I have multiple external files e,g.onlineuser20200414.txt , onlineuser20200415.txt, Userxyz.txt in a input folder location "/loc/sasdataset/lev1" now the latest file i.e., onlineuser20200415.txt from that location I have to extract into a dataset and will be moved to different archived folder location "/loc/sasdataset/xyz" and if any file aged more than 30 days e.g onlineuser20200314.txt will be automatically deleted from the location "/loc/sasdataset/xyz". How can I find the latest file and extract it into a dataset in sas EG? Please if anybody give a code example.
Thanks in advance
Edited
In SQL, query DICTIONARY.TABLES to find the latest. Note that if you always MOVE files, you will (in the long run) only find one dataset (the most recently added) anyway.
How did you query DICTIONARY.TABLES? Please post your code, using the "little running man" button.
Are these SAS tables or some external files on disk?
@annypanny wrote:
sas tables
Why did your original post use .txt extension on the file names if they are SAS datasets? SAS datasets use .sas7bat as the extension. DICTIONARY.TABLES will not show text files. Just datasets (and then only for places pointed to by active librefs).
It did not have the .txt, that's why I suggested using the dictionary tables. But we seem to have a goalpost-mover here.
To the OP: please add a line declaring the edit if you have to edit one of your posts (except if it's just correcting a typo).
If I had known that you were talking about external text files, I would not have suggested the dictionary tables at all.
So what are we really talking about, datasets or external files?
Then dictionary.tables is the way to go. Show the SQL code that you tried, post the log from it using the </> button.
</filename file "/sas/sasdataset/lev1/";
data latest;
set file.latest;
run;
create view file as select * from dictionary.tables; |
/>
To find SAS datasets, define a libname for the directory, then use DICTIONARY.TABLES:
libname file "/sas/sasdataset/lev1/";
proc sql;
create table datasets_in_file as
select *
from dictionary.tables
where libname = 'FILE' /* always use uppercase for libnames and memnames */
;
quit;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.