DATA Step, Macro, Functions and more

ERROR: There were 1 unclosed %DO statements.

Reply
Occasional Contributor
Posts: 14

ERROR: There were 1 unclosed %DO statements.

The intention of this code to get every permutation of copay onto one line for the 3 by variables listed within the macro.  (i.e. SubscriberCopay_Crowns, SpouseCopay_Crowns, etc... for 5 different relationships , for 20 types of services).

I've written loops on many occasions but this one in particular is giving me an error as specified in the discussion title.

proc sql;
  select distinct translate(translate(trim(ValidRelationshipDescription),'_','/'),'_',' ')
  into :Relationship1 - :Relationship5 from copay2;
quit;

proc sql;
  select distinct _NAME_ into Smiley Frustratedervice1 - Smiley Frustratedervice20 from copay3;
quit;

%macro expand;
data copay4;
  set copay3;
  by Groupnumber NetworkGroupID NetworkGroupIDDescription;
   %do i = 1 %to 5;
      %do k = 1 %to 20;
    %if first.NetworkGroupID %then %do;
     %if _NAME_ = "&&service&k.." %then %do;
     &&Relationship&i.._&&Service&k.. = &&Relationship&i..;
     %end;
   %end;
%end;
run;
%mend expand;
%expand;

dataset copay3 example line:

Groupnumber, NetworkGroupID, NetworkGroupIDDescription, _NAME_, Any, Dependants_Only, Subscriber_Spouse, Subscriber_Only, Spouse_Dependants

00000-00001                  1                         All Networks                        Crown    50                    .                           .                                .                         .

Super User
Posts: 19,861

Re: ERROR: There were 1 unclosed %DO statements.

Posted in reply to Data_Detective_23219

You have 4 %do and 3 %end so the error is correct.

You need to add another %end or remove a %do

Super User
Posts: 11,343

Re: ERROR: There were 1 unclosed %DO statements.

Posted in reply to Data_Detective_23219

My guess would be that this construct:

     %if _NAME_ = "&&service&k.." %then %do;

     &&Relationship&i.._&&Service&k.. = &&Relationship&i..;

should be:

     %if _NAME_ = "&&service&k.." %then

     &&Relationship&i.._&&Service&k.. = &&Relationship&i..;

Occasional Contributor
Posts: 14

Re: ERROR: There were 1 unclosed %DO statements.

Thanks ballardw.  Your answer was correct.  I had a redundant do in my condition.  Suprising I can still get completely flummoxed by such trivial errors.

Ask a Question
Discussion stats
  • 3 replies
  • 1798 views
  • 1 like
  • 3 in conversation