BookmarkSubscribeRSS Feed
annypanny
Quartz | Level 8

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

 

20 REPLIES 20
annypanny
Quartz | Level 8
hi, I used DICTIONARY.TABLES but it did'nt work for me, I just wanted to move the latest file in to the folder, how can I, can MACROS makes my life easier?
Patrick
Opal | Level 21

Are these SAS tables or some external files on disk?

Tom
Super User Tom
Super User

@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).

Kurt_Bremser
Super User

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.

annypanny
Quartz | Level 8

</filename file "/sas/sasdataset/lev1/";

data latest;

set file.latest;

run;

create view file as select * from dictionary.tables;

/>

Kurt_Bremser
Super User

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;
annypanny
Quartz | Level 8
and what if it is a extrnal file not sas dataset? just asking for curiosity then we can't use libname then how can I do that?

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 20 replies
  • 2642 views
  • 9 likes
  • 5 in conversation