BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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
Meteorite | Level 14

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;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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