DATA Step, Macro, Functions and more

what in this code would cause the error 'there was 1 unclosed do block'?

Reply
Occasional Contributor
Posts: 13

what in this code would cause the error 'there was 1 unclosed do block'?


one do one end .....is there something else needed to  close this do block?

data da;

      merge output.da_med (in=in1) output.da_rx (in=in2); *merge the ones and zeroes produced by CDPS and MRX above;

      by recipno;

      if _n_ = 1 then set weight_dac; *insert the weights on every record;

    aidcat = 'DA';

      %bridge; *run the bridge code macro;

      *set up arrays to facilitate multiplication of a large list of variables;

      array ind

  • &
  • list. CCARVH CCARM CCNSH CPULVH CPULH CGIH CMETH CHIVM CINFM CHEMEH ;

          array fac

  • &
  • factors. CCARVH_fac CCARM_fac CCNSH_fac CPULVH_fac CPULH_fac CGIH_fac CMETH_fac CHIVM_fac

                                           CINFM_fac CHEMEH_fac;

          risk_score = intercept_fac; *intercept must be added to every risk score;

          do i = 1 to dim(fac);

                *cycle through all the 1/0s and factors, multiply them together, and add them to the risk score field;

                risk_score = risk_score + ind * fac;

          end;

          drop intercept_fac &factors. i CCARVH_fac CCARM_fac CCNSH_fac CPULVH_fac CPULH_fac CGIH_fac CMETH_fac CHIVM_fac

                 CINFM_fac CHEMEH_fac aid;

    run;

    Thx

    Trusted Advisor
    Posts: 1,607

    Re: what in this code would cause the error 'there was 1 unclosed do block'?

    We can't provide an answer, you haven't shown us what is in %bridge

    Occasional Contributor
    Posts: 13

    Re: what in this code would cause the error 'there was 1 unclosed do block'?

    Here is the full code-thank you for your efforts...

    Attachment
    Trusted Advisor
    Posts: 1,607

    Re: what in this code would cause the error 'there was 1 unclosed do block'?

    Great, so somewhere in %bridge, there is an unclosed do block.

    Your task is then to go through %bridge and figure out where this unclosed do block is.

    Occasional Contributor
    Posts: 6

    Re: what in this code would cause the error 'there was 1 unclosed do block'?

    Agreed with PaigeMiller, I think in the last line of Bridge some problem is there.

    Occasional Contributor
    Posts: 13

    Re: what in this code would cause the error 'there was 1 unclosed do block'?

    ok, that is what I am asking about...I can't find it....I think I have matched up all of the do and ends.....am I matching up the wrong things......I thought a do block started with 'do' and ended with 'end'

    PROC Star
    Posts: 7,356

    Re: what in this code would cause the error 'there was 1 unclosed do block'?

    What about the code for the other macro you call?  You didn't include it?  Also, when you call a macro, the line shouldn't end with a semicolon.

    Yes, your understanding is correct.

    Occasional Contributor
    Posts: 13

    Re: what in this code would cause the error 'there was 1 unclosed do block'?

    THx, I will check it again

    Super User
    Posts: 17,750

    Re: what in this code would cause the error 'there was 1 unclosed do block'?

    If you're absolutely stuck and can't find the end to match a do, start numbering them.

    do start=1 to 20; /*1*/

         some code...;

         do test=1 to 50; /*2*/

         some more code...;

         end ;/*2*/

    end;/*1*/

    Occasional Contributor
    Posts: 13

    Re: what in this code would cause the error 'there was 1 unclosed do block'?

    that is a great idea!  thx

    Community Manager
    Posts: 2,757

    Re: what in this code would cause the error 'there was 1 unclosed do block'?

    If you have SAS Enterprise Guide 4.3 or 5.1, you might try running this (and the macros that it references) through the code formatter:

    http://blogs.sas.com/content/sasdummy/2010/12/23/the-sas-code-formatter-more-than-a-pretty-face/

    Chris

    Super User
    Super User
    Posts: 6,497

    Re: what in this code would cause the error 'there was 1 unclosed do block'?

    The lines in that file are way too long for human consumption.

    And SAS might even have trouble with them depending on the version you are using and the settings.

    I suspect that some lines are being truncated.

    Especially because the %BRIDGE macro has a couple of END statements out past column 165!!!!

    Trusted Advisor
    Posts: 1,607

    Re: what in this code would cause the error 'there was 1 unclosed do block'?

    I agree with Tom

    While the problem may or may not be in %Bridge, the way things are written, in one long line "way too long for human consumption", the appearance of the code hinders debugging and understanding. This code ought to be one command per line, and properly indented. My eyes are not used to looking at code written like this, it hurts my brain to look at code written like this, and so even though I was being unhelpful, I didn't even try to see if I could find a problem in this code.

    Super User
    Posts: 10,466

    Re: what in this code would cause the error 'there was 1 unclosed do block'?

    Run the code with OPTIONS MPRINT to see if there's anothe DO block in any of your macros.

    BTW, becareful habitually ending references to macro variables with a period when you aren't actually concatenating something.

    Super User
    Posts: 10,466

    Re: what in this code would cause the error 'there was 1 unclosed do block'?

    I ran a piece of code using 1 for the value of all of the  variables and only the BRIDGE macro as shown in your attachment and did not get any message about unclosed do loop (see code at bottom).

    At this point point I would start with the offending datastep and comment out all the statements and the add them back in one at a time (with loops the start and end count as one statement for this process - but do run with the stuff inside the loops commented out).

    I would also make sure the other macros CDPS and MRX do not contain definitions of or modify the BRIDGE macro.

     

    data junk;

    Retain &list &factors 1;

    aidcat = 'DA';

    %bridge

    run;

    Ask a Question
    Discussion stats
    • 15 replies
    • 3015 views
    • 4 likes
    • 9 in conversation