BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

Hello

I have list of dates and I need to import files with these dates.

For example:

For the dates 190125+191117+191214  I need to import 3 files: RawTbl1901025, RawTbl191117,RawTbl191214

The problem is that sometimes the file doesn't exists and then I need to import the file one day before and if not exists then two days before etc....

Let's say that the loop should Run until 10 days before( because it is impossible that the file doesn't exist more than 10 days before..)

What is the way to do it please?

Please note that the dates can be in macro var or in data set

%let vector=190125+191117+191214; 
%let n=3;

/*OR in data set*/
Data datesTbl;
input date $;
cards;
190125
191117
191214
;
run;

%macro import; %do j=1 %to 3; %let YYMMDD=%scan(&vector.,&j.,+); data RawTbl&YYMMDD; infile "/pth/ttbl&YYMMDD..TXT" recfm=f LRECL=25; input Branch s370fib2. customerID s370fib4. KOD s370fib2. Team s370fib2. Type $ebcdic2. ; snif_amt=compress(snif); date=&YYMMDD; run; %mend import; %import;

 

4 REPLIES 4
PaigeMiller
Diamond | Level 26

We always advise you to handle dates as integers representing the number of days since 1/1/1960. That way, it becomes very easy to figure out what day is 10 days before 03MAR19, using the INTNX function, or even simpler by plain subtraction of 10.

 

You need to go back and re-formulate your solution to do the calculations using actual SAS date values and subtraction. Use formatting to turn the result into something like 1901025.

 

By the way, what does that 7 digit string 1901025 represent anyway?

--
Paige Miller
Ronein
Meteorite | Level 14

Sorry, it is 1901025 (YYMMDD )

PaigeMiller
Diamond | Level 26

@Ronein wrote:

Sorry, it is 1901025 (YYMMDD )


That's still 7 digits, and it is NOT YYMMDD

--
Paige Miller
Kurt_Bremser
Super User

Once again, no macro needed, only one macro variable:

Data datesTbl;
input date :yymmdd6.;
format date yymmddn6.;
cards;
190125
191117
191214
;
run;

proc sql noprint;
select quote('/pth/ttbl'!!put(date,yymmddn6.)!!'.TXT')
into :infiles separated by ','
from datestbl;
quit;
%put &infiles; /* just for checking */

filename infiles (&infiles) recfm=f lrecl=25;

data RawTbl;
length fname $256;
infile infiles filename=fname;
input 
 Branch s370fib2.
 customerID s370fib4.
 KOD s370fib2.
 Team s370fib2.  
 Type  $ebcdic2. 
;
snif_amt=compress(snif);
date = input(substr(fname,length(fname-9),6),yymmdd6.);
run;

and all data goes into one dataset automatically.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 476 views
  • 0 likes
  • 3 in conversation