DATA Step, Macro, Functions and more

Multiple arrays in same data step

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 121
Accepted Solution

Multiple arrays in same data step

Hi!  I'm looking for help with this array.  I want to check multiple variables (Secondarydiagnosis1-20, Procedure1-20, and ProcedureHCPCS_1-13)   for a number starting with '493'.  If it begins with '493' then new variable asthma=1.  I submitted this code but it is taking a long time to process, so I'm sure there is an error!  Help is appreciated!

 

 

data asthma2.asthma_only;
set asthma2.fyall_EXCL_F;
asthma=0;
array  dx(*)secondarydiagnosis2-secondarydiagnosis20;
do i= 1 to dim(dx);
if dx(i) =: '493' then asthma=1;
array proc(*) procedure1-procedure20;
do i=1 to dim(proc);
if proc(i)=:'493' then asthma=1;
array HCPCS(*) ProcedureHCPCS_1-ProcedureHCPCS_13;
do i=1 to dim(HCPCS);
if hcpcs(i)=:'493' then asthma=1;
end;
end;
end;
run;


Accepted Solutions
Solution
‎01-09-2017 02:30 PM
Super User
Posts: 5,079

Re: Multiple arrays in same data step

Yes, your DO loops should not be nested.  Moving a few END statements would work:

 

data asthma2.asthma_only;
set asthma2.fyall_EXCL_F;
asthma=0;
array  dx(*)secondarydiagnosis2-secondarydiagnosis20;
do i= 1 to dim(dx);
if dx(i) =: '493' then asthma=1;

end;
array proc(*) procedure1-procedure20;
if asthma=0 then do i=1 to dim(proc);
if proc(i)=:'493' then asthma=1;

end;
array HCPCS(*) ProcedureHCPCS_1-ProcedureHCPCS_13;
if asthma=0 then do i=1 to dim(HCPCS);
if hcpcs(i)=:'493' then asthma=1;
end;
run;

 

View solution in original post


All Replies
Solution
‎01-09-2017 02:30 PM
Super User
Posts: 5,079

Re: Multiple arrays in same data step

Yes, your DO loops should not be nested.  Moving a few END statements would work:

 

data asthma2.asthma_only;
set asthma2.fyall_EXCL_F;
asthma=0;
array  dx(*)secondarydiagnosis2-secondarydiagnosis20;
do i= 1 to dim(dx);
if dx(i) =: '493' then asthma=1;

end;
array proc(*) procedure1-procedure20;
if asthma=0 then do i=1 to dim(proc);
if proc(i)=:'493' then asthma=1;

end;
array HCPCS(*) ProcedureHCPCS_1-ProcedureHCPCS_13;
if asthma=0 then do i=1 to dim(HCPCS);
if hcpcs(i)=:'493' then asthma=1;
end;
run;

 

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 129 views
  • 0 likes
  • 2 in conversation