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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 942 views
  • 0 likes
  • 2 in conversation