Hello,
SAS is running the following code but results are not being generated. I'm running Enterprise Guide 7.12.
%macro abc;
data want;
set have;
%do num=1 %to 25;
%if diag_code&num. in ("Z590", "Z591", "Z598") %then
dcheck&num.=1;
%end;
run;
%mend;
%abc;
run;
Thanks
You could switch to arrays, as suggested. Then you wouldn't need any macro language at all. However, you can get macro language to do the job easily enough by cutting out a couple of percent signs:
%macro abc;
data want;
set have;
%do num=1 %to 25;
if diag_code&num. in ("Z590", "Z591", "Z598") then
dcheck&num.=1;
%end;
run;
%mend;
%abc
The idea is to have the DATA step process the data. The role of macro language is to make sure that the correct DATA step code gets generated.
You could switch to arrays, as suggested. Then you wouldn't need any macro language at all. However, you can get macro language to do the job easily enough by cutting out a couple of percent signs:
%macro abc;
data want;
set have;
%do num=1 %to 25;
if diag_code&num. in ("Z590", "Z591", "Z598") then
dcheck&num.=1;
%end;
run;
%mend;
%abc
The idea is to have the DATA step process the data. The role of macro language is to make sure that the correct DATA step code gets generated.
@torvyle wrote:
Hello,
SAS is running the following code but results are not being generated. I'm running Enterprise Guide 7.12.
%macro abc; data want; set have; %do num=1 %to 25; %if diag_code&num. in ("Z590", "Z591", "Z598") %then dcheck&num.=1; %end; run; %mend; %abc; run;
Thanks
Do not use the macro language for manipulating data. Macro language is for manipulating code.
Use the data step's tools for this:
data want;
set have;
array diags {*} diag_code1-diag_code25;
array checks {*} dcheck1-dcheck25;
do num = 1 to 25;
if diags{num} in ("Z590", "Z591", "Z598")
then checks{num} = 1;
end;
drop num;
run;
Thanks, everyone. KurtBremser's solution works too.
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!SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.