BookmarkSubscribeRSS Feed
emaguin
Quartz | Level 8

What i want is an if-else if (i won't need an else statement for this problem) structure so that if a statement or set of statements within an if/else if is executed the rest of the structure is not executed. in the log output everything seems to go ok until the fifth else if block where for unknown to me reasons an if-then is expected.

If i take out the 'else's, it will run but isn't that equivalent to a set of if-then statements, all of which are executed?

(also, you'll see a vdu{1} referenced. That is defined above this block of syntax and i do not believe is the problem).

 

625 array voderr(12) ODERR1-ODERR12;
626 if (A3ODRG90 eq 1 or A3ODRG90 eq .p) then
627 do i=1 to 12;
628 voderr{i}=0;
629 nval=0;
630 k=(i-1)*9;
631 do j=1 to 7;
632 if (vdu{k+j} eq 1) then nval=sum(of nval,1);
633 end;
634 * j=8 IS DNU, j=9 IS PNA;
635 * possible cases;
636 * nval=0, DNU=1, PNA=. no error. A3ODxxW1-A3ODxxW7=0, A3ODxxW9=0;
637 if (nval eq 0 and vdu{k+8} eq 1 and vdu{k+9} eq .) then do;
638 do j=1 to 7;
639 vdu{k+j}=0;
640 end;
641 vdu{k+9}=0;
642 voderr{i}=0;
643 end;
644 * nval=0, DNU=., PNA=1 no error. A3ODxxW1-A3ODxxW7=.p, A3ODxxW8=0;
645 else if (nval eq 0 and vdu{k+8} eq . and vdu{k+9} eq 1) then do;
646 do j=1 to 7;
647 vdu{k+j}=.p;
648 end;
649 vdu{k+8}=0;
650 voderr{i}=0;
651 end;
652 * nval=0, DNU=., PNA=. no error. A3ODxxW1-A3ODxxW9=.p;
653 else if (nval eq 0 and vdu{k+8} eq . and vdu{k+9} eq .) then do;
654 do j=1 to 7;
655 vdu{k+j}=.p;
656 end;
657 vdu{k+8}=0;
658 vdu{k+9}=0;
659 voderr{i}=0;
660 end;
661 * nval>0, DNU=., PNA=. no error. A3ODxxW1-A3ODxxW9: recode . to 0;
662 else if (nval gt 0 and vdu{k+8} eq . and vdu{k+9} eq .) then do;
663 do j=1 to 7;
664 if (vdu{k+j} ne 1) then vdu{k+j}=0;
665 end;
666 vdu{k+8}=0;
667 vdu{k+9}=0;
668 voderr{i}=0;
669 end;
670 * nval=0, DNU=1, PNA=1 error. do what? TYPE 1 ERROR;
671 else if (nval eq 0 and vdu{k+8} eq 1 and vdu{k+9} eq 1)
672 then voderr{i}=1; /* ERROR TYPE 1: e.g., 000000011 */;
673 * nval>0, DNU=1, PNA=. error. do what? TYPE 2 ERROR;
674 else if (nval ge 1 and vdu{k+8} eq 1 and vdu{k+9} eq .)
----
160
ERROR 160-185: No matching IF-THEN clause.

675 then voderr{i}=2; /* ERROR TYPE 2: e.g., 10000001. */;
676 * nval>0, DNU=., PNA=1 error. do what? TYPE 3 ERROR;
677 else if (nval ge 1 and vdu{k+8} eq . and vdu{k++9} eq 1)
----
160
ERROR 160-185: No matching IF-THEN clause.

678 then voderr{i}=3; /* ERROR TYPE 3: e.g., 1000000.1 */;
679 * nval>0, DNU=1, PNA=1 error. do what? TYPE 4 ERROR;
680 else if (nval ge 1 and vdu{k+8} eq 1 and vdu{k++9} eq 1)
----
160
ERROR 160-185: No matching IF-THEN clause.

681 then voderr{i}=4; /* ERROR TYPE 4: e.g., 100000011 */;
682 end;
683 ANYODERR=sum(of ODERR1-ODERR12);
684 run;

 

3 REPLIES 3
FreelanceReinh
Jade | Level 19

Hello @emaguin,

 

Remove the unnecessary semicolons after the "/* ... */" comments (see log lines 672, 675, 678 and 681). They break the connection between the IF-THEN and ELSE statements, hence the error messages.

ballardw
Super User

Format your code and then paste into a text box opened on the forum with the </> icon.

Start at the beginning not part way through the step. You may have an issue started before the code you show.

ChrisHemedinger
Community Manager

I copied your code, stripped the line numbers and errors, and pasted into SAS Enterprise Guide. Then I used the Format Code feature to see the if/then and do/end matchups.  I noticed this:

ifelse.jpg

You don't use the do..end wrapper for these, but you do have an extra semicolon at each line and that might be an issue. When in doubt (even with just one code instruction after the then, put it in a do/end. Then if you have to add an additional statement later you're already covered.

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 564 views
  • 3 likes
  • 4 in conversation