Thank you very much, but I'd like to ask you a question. Thank you
Code as follws:
%macro Sets(start,end,prefix); %do i = start %to end; &prefix.||&i.||' ' %end; %mend;
%Sets(2005,2050,data);
I want to generate a program like this:
data2005 data2006 data2007 ......data2050;But my macro does not run successfully, how to modify this macro program
To use macro parameters in the macro, you need to address them like macro variables, and you do not need concatenation operators, as in macro everything is text:
%macro Sets(start,end,prefix);
%do i = &start. %to &end.;
&prefix.&i
%end;
%mend;
You can use this like this:
data want;
set
&sets(2005,2050,data)
; /* this semicolon is NOT part of the macro call, it terminates the SET statement! */
run;
I want to use this macro program for the following program
data WeekOfDate;
set %sets(start=2005,end=2020,prefix=data);
run;
A few corrections.
Hope this helps 🙂
%macro Sets(start,end,prefix);
%do i = &start. %to &end.;
&prefix.&i.
%end;
%mend;
%put %Sets(2005,2050,data);
To use macro parameters in the macro, you need to address them like macro variables, and you do not need concatenation operators, as in macro everything is text:
%macro Sets(start,end,prefix);
%do i = &start. %to &end.;
&prefix.&i
%end;
%mend;
You can use this like this:
data want;
set
&sets(2005,2050,data)
; /* this semicolon is NOT part of the macro call, it terminates the SET statement! */
run;
First of all, thank you very much.
But,if you have two data set names 'data2005','data2006'。
now,use programs as follows:
/*define*/
%macro Sets(start,end,prefix);
%do i = &start. %to &end.;
&prefix.&i.
%end;
%mend;
data a;
set
%Set(2005,2006,data)
;
run;
Unfortunately, the program will not run。
You define macro Sets, but you use macro set (missing s).
If something else is the issue, please post the complete log of the data step, using this button:
I'm very sorry for wasting your time, and I would like to express my heartfelt thanks for your help!
@Phoenix_LJ wrote:
I'm very sorry for wasting your time, and I would like to express my heartfelt thanks for your help!
Really no waste, sometimes a second set of eyes is needed. Been there, done that, have the T-shirt.
Might be material for another Maxim.
Why does it not run? What does the log say?
Proof of concept:
data data2005;
set sashelp.class;
run;
data data2006;
set sashelp.class;
run;
%macro Sets(start,end,prefix);
%do i = &start. %to &end.;
&prefix.&i
%end;
%mend;
data want;
set
%Sets(2005,2006,data)
;
run;
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!
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.