DATA Step, Macro, Functions and more

Sequence File Importing Based on Text File Creation/Modified Date?

Reply
Regular Contributor
Posts: 164

Sequence File Importing Based on Text File Creation/Modified Date?

Hi

 

I can't find the post that I originally used so I can cite the programmer but someone on the site helped me create a pipe that allows the files to be imported sequentially.  The reason I need that is because later files could be making corrections on earlier abstracts so the newer file data must be the row of data used when looking at multiples of the same abstract.

 

This worked well before because the files are named sequentially i.e. C001, C002 etc.  But now the company is using a new software program so there will be files with the same file name so I need to now sequence by file date.

 

Previous code looked like this:

FILENAME FILES PIPE "DIR F:\TEST\TEST_FILES\*.TXT /B /O:N";

Data Have;
INFILE FILES TRUNCOVER END=LAST;
INPUT FNAME $250.;
FNAME="F:\TEST\TEST_FILES\"||Trim(Left(FNAME));
run;

The the data extraction looks like this (I won't list all fields):

 

Data DataA;
set Have;
INFILE IN FILEVAR=FNAME END=EOF
LRECL=5000
Truncover
firstobs=2;

Do Until (EOF);
input @1   Field1 $1.


So how do I now change it so the "Have" is also including the date of the file?  Or sequence by date and add another sequencial number to the file name?  Thanks for any and all assistance.

 

 

Shelley

Super User
Posts: 7,768

Re: Sequence File Importing Based on Text File Creation/Modified Date?

I just fiddled around with the DOS (what a fitting acronym!) dir command, and sadly, it does not provide an option for getting exactly the output you need.

So you will have to use it without the /b option and parse the output, as it contains lines you don't want which need to be discarded, and you need to read the columns correctly.

OTOH, the output of dir is at least formatted in a consistent way that allows formatted input with column prefixes.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 11,343

Re: Sequence File Importing Based on Text File Creation/Modified Date?

I believe that the DIR switch /OSmiley Very Happy will sort the pipe output with oldest first and /O:-D by newest first if that helps. BUT you will need to remove the /B (bare)  for dates to display and parse the output.

The /T switch control which time field is displayed or used. /T:C would use creation and /T:W last writtend

Regular Contributor
Posts: 164

Re: Sequence File Importing Based on Text File Creation/Modified Date?

Thanks for your responses.  I'll check out your suggestions and see what I can come up with.  The code I have already uses /O so maybe it is sorting in that order and not in number order as I assumed.

Ask a Question
Discussion stats
  • 3 replies
  • 181 views
  • 1 like
  • 3 in conversation