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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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