Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If then and do loop

Status
Not open for further replies.

roland9

Technical User
Feb 8, 2006
17
US
Can someone please tell me for the following output

capacity airplanetype staff
150 Large 10

why the first code works and the second doesnt...

CODE_1
data work.test;
capacity = 150;
if 100 le capacity le 200 then
do;
airplanetype = 'Large';
staff = 10;
end;
else
do;
airplanetype = 'Small';
staff = 5;
end;
run;

CODE_2
data work.test;
capacity = 150;
if 100 le capacity le 200 then
airplanetype = 'Large' and staff = 10;
else airplanetype = 'Small' and staff = 5;

Thanks
run;
 
Hey it would be great if someone can tell me this by latest tomm morning as I have an exam which may consits of questions like these..

Thanks
 
Sorry, it's too late for your exam, but if it's still of use to you, the problem is this line:-
Code:
if 100 le capacity le 200 then
airplanetype = 'Large' and staff = 10;

You cannot use AND in this context. You can say "if A=B AND C=D" but you cannot say "A=B AND C=D" You have to use the "DO.... END" construction as in the first example.
 
Hey thanks that helps.Sometimes just oversee these minute logical details.This seems to be a good forum to get some doubts cleared..
 
You never get out of the stage of overlooking your own simple errors, but as time goes on, you find it easier to spot other peoples. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top