BookmarkSubscribeRSS Feed
shellp55
Quartz | Level 8

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

3 REPLIES 3
Kurt_Bremser
Super User

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.

ballardw
Super User

I believe that the DIR switch /O:D 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

shellp55
Quartz | Level 8

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.

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
  • 823 views
  • 1 like
  • 3 in conversation