- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks.