BookmarkSubscribeRSS Feed
fsuzhang
Fluorite | Level 6

I need to read in data set htn_etg_diag21549

 

I using the following code to build my file name and read, the following code show wield outcomes

 

data _null_;
%let date="2018-12-31";
call symput ('date_2',input(&date.,yymmdd10.));
%put &date_2.;
run;

 

data _null_;
%let date="2018-12-31";
call symput ('date_2',input(date,yymmdd10.));
%put &date_2.;
run;

data test;
date="2018-12-31";
call symput ("date1",input(date,yymmdd10.));
%put &date1.;
%let date2=%sysfunc(strip(&date1.));
/* time_slept=sleep(20,1); */
%put &date2.;
%let name=htn_etg_diag&date2.;
%put &name.;
set &name.;
run;

 

data _null_;
%let date="2018-12-31";
call symput ('date_2',input(date,yymmdd10.));
%put &date_2.;

/* 21549 is expected*/
run;

 

data test;
date="2018-12-31";
call symput ("date1",input(date,yymmdd10.));
%put &date1.;
%let date2=%sysfunc(strip(&date1.));
/* time_slept=sleep(20,1); */
%put &date2.;
%let name=htn_etg_diag&date2.;
%put &name.;
set &name.;
run;.

 

the above code can not work well, however, after submitted several time, it works, but if close the SAS and resubmit them, not working, only works after several submissions.

 

what's the problem.

2 REPLIES 2
ballardw
Super User

Without more specifics it is hard to address your problem. In general though Macro variables created in a data step are not useable in that step and macro statements such as in

data _null_;
%let date="2018-12-31";
call symput ('date_2',input(&date.,yymmdd10.));
%put &date_2.;
run;

are timing dependent. What you might be intending with above should be done as:

%let date="2018-12-31";
data _null_;
   call symput ('date_2',input(&date.,yymmdd10.));
run;
%put &date_2.;

or

%let date=2018-12-31;
%let date_2 = %sysfunc(inputn(&date.,yymmdd10.));
%put &date_2.;

Generally it going to work out much better if you do all of the macro stuff before the data step to avoid the timing issues.

Instead of

data test;
date="2018-12-31";
call symput ("date1",input(date,yymmdd10.));
%put &date1.;
%let date2=%sysfunc(strip(&date1.));
/* time_slept=sleep(20,1); */
%put &date2.;
%let name=htn_etg_diag&date2.;
%put &name.;
set &name.;
run;

something more like:

%let date=2018-12-31;
%let date_2 = %sysfunc(inputn(&date.,yymmdd10.));
%let name=htn_etg_diag&date_2.;

data test;
   set &name.;
run;

The reason it took several times before anything would run was the macro variables you created were not available in the data steps the first time your ran the code. The second or later time then they MAY have existed from the previous attempt.

 

 

fsuzhang
Fluorite | Level 6

Thanks.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 398 views
  • 0 likes
  • 2 in conversation