BookmarkSubscribeRSS Feed
sassharp
Calcite | Level 5

10 or less files comes to directory /abc/landing with timestamp everyday. filenames are like a_yyyymmddhhmmss.dat, b_yyyymmddhhmmss.dat etc., 

sometimes there is a possibility of duplication of files with same content with different different timestamp for sameday. need to select latest time stamped file.

 

1)if 10 distinct files are there in /abc/landing/ , read all files to convert into SAS data sets.

 

2)if there are less than 10 files, create a subdirectory withtimestamp from filenames under /abc/landing, /abc/landing/withtimestamp keep those less numbered files into this /abc/landing/withtimestamp and wait and check the /abc/landing untill you get a remaining files with same timestamp.

 

3)should look /abc/landing everyday to process 10 distinct files available with same dated ones. if there are more than 10 files, should look for a) are there any duplicated files? if so, select 10 distinct files with latest timestamp b) are there any old dated files there. if there are any old dated files send them to respective dated folder and look in that respective folder enough 10 files are there to read those 10 files and delete that respective date directory.

 

 

Any documentation or papers links avilable appreciated. Thanks.

3 REPLIES 3
dcruik
Lapis Lazuli | Level 10

I'm not sure what type of operating system you are using, but I know using the FILENAME with a PIPE command, you can read files from a directory and create new directories and such.  You just need to specify the operating system command (depending on the OS you are on).  For example, creating a new directory and then copying and pasting files from one directory to the new directory:

/*** Create new directory ***/
filename f1 pipe 'mkdir "c:\projects\target"';
data _null_;
	infile f1;
	input;
	put _infile_;
run;

/*** Copy files and paste in new directory ***/
filename f2 pipe 'copy "C:\projects\output" "c:\projects\target"';
data _null_;
	infile f2;
	input;
	put _infile_;
run; 
sassharp
Calcite | Level 5

OS is UNIX

dcruik
Lapis Lazuli | Level 10

I would recommend looking into and doing some research on the X or PIPE command inside of SAS.  They both allow you to use UNIX code to open and look at files in directories and create new directories and such.  I'm sure you could create something that utilized one of those and some SAS language to get what you need.

 

http://support.sas.com/documentation/cdl/en/hostunx/61879/HTML/default/viewer.htm#a000290413.htm

 

or

 

http://support.sas.com/documentation/cdl/en/hostunx/61879/HTML/default/viewer.htm#pipe.htm

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 921 views
  • 0 likes
  • 2 in conversation