BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello,

I want to import CSV files into SAS.

I wan to create a series of dates and import files with names of these dates.

Why Way B in this code is not working?

What is the way to solve it please?

In Way B there is only one CSV file that is imported   with date 20210511.

Why?

 

%macro import_one(YYYYMMDD);
%if %sysfunc(fileexist(/path/Revenue&YYYYMMDD.))
%then %do;
data t&YYYYMMDD.;
infile "/path/Revenue&YYYYMMDD."
dlm=';' dsd truncover firstobs=2;
input VAR1-VAR59;
run;
%end;
/*If doesnt exist then create empty data set*/
%else %do;
data t&YYYYMMDD.;
Format VAR1-VAR59 8.;
stop;
run;
%end;
%mend import_one;

/**Way A-Working well**/
Data datestbl;
input YYYYMMDD $;
call execute('%nrstr(%import_one('!!YYYYMMDD!!'))');
cards;
20210501
20210502
20210503
20210504
20210505
20210506
20210507
20210508
20210509
20210510
;
Run;

/**Way B-Not Working well**/
%let start_date=01MAY2021;
%let end_date=10MAY2021;
data datestbl(keep=YYYYMMDD);
date="&start_date"d;
YYYYMMDD=put(date,yymmddn8.);
do while (date<="&end_date"d);
    output;
    date=intnx('day', date, 1, 's');
	YYYYMMDD=put(date,yymmddn8.);
end;
format date date9.;
call execute('%nrstr(%import_one('!!YYYYMMDD!!'))');
run;
 
3 REPLIES 3
Ronein
Onyx | Level 15

Do you mean that I need to write call execute within the loop?

 %let start_date=01MAY2021;

%let end_date=10MAY2021;

data datestbl(keep=YYYYMMDD);

date="&start_date"d;

YYYYMMDD=put(date,yymmddn8.);

do while (date<="&end_date"d);  

output;  

date=intnx('day', date, 1, 's');    

YYYYMMDD=put(date,yymmddn8.);

call execute('%nrstr(%import_one('!!YYYYMMDD!!'))');

end;

 run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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