BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

data have;

input name $ level;

cards;

Frank 1

Joan 2

Sui 2

Jose 3

Burt 4

Kelly .

Juan 1

run;

 

data want;

set work.levels;

if level=. then exp="unknown";

else if level=1 then exp="Low";

else if level = 2 or 3 then exp="Medium";

else  exp="High";

run;

 

Which of the following is correct

 

A)Low,Medium,High

B)Low,Medium,High,Unknown

C)Low,Medium,High,Unknown and high

D)Low,Medium,High,Unknown, high, and (missing character values)

 

Answer : B

 

Could someone please suggest why it is B not C.. Many thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

I'm happy to answer, but you do have to ask a question. Where in your post is a question? You have the multiple choice answers but no actual question posted. 

 

Exact Question:

https://communities.sas.com/t5/SAS-Programming/IF-ELSE-IF-CONDITION/m-p/497308/highlight/true#M13176...

 

I can only respond to what I see posted, the code is incorrect and would not run, not sure why it's a problem to say that when it's clearly true. How am I supposed to know if that's part of the question or if it's a mistake you made? I can only see what you've posted. 

 

https://communities.sas.com/t5/SAS-Support-Communities/How-to-ask-a-good-question-and-receive-a-fast...


@rajeshalwayswel wrote:

 

  @reeza if you don't want to answer please won't reply to the question someone 
will answer in a hurry I didn't check the code. This is my code

View solution in original post

7 REPLIES 7
kiranv_
Rhodochrosite | Level 12

change your code to below level = 3 is missing. becacuase there is no "high" assigned and change your dataset name in set statement to have instead of levels

 

 

data want;

set work.have;

if level=. then exp="unknown";

else if level=1 then exp="Low";

else if level = 2 or level = 3 then exp="Medium";

else  exp="High";

run;

 

rajeshalwayswel
Pyrite | Level 9
Yes High is not assigned? Can you explain in detail please. Why High not assigned.
kiranv_
Rhodochrosite | Level 12

because you have "High" not "high" in your else statement.

 

 else if level = 2 or 3 then exp="Medium";

change it to 

 

 else if level = 2 or level = 3 then exp="Medium";

 

Reeza
Super User

1. The code is wrong and would never run - it refers to the wrong data set

2. What is the question that is being asked? That's not anywhere in the post. 

3. Why not run it and check the answer? 

 

This exact or very similar question has been asked before, if you search you'll likely find the answer to whatever the question is and the logic. None of the answers are correct as the code posted won't run and HIGH will never be assigned.

 


@rajeshalwayswel wrote:

data have;

input name $ level;

cards;

Frank 1

Joan 2

Sui 2

Jose 3

Burt 4

Kelly .

Juan 1

run;

 

data want;

set work.levels;

if level=. then exp="unknown";

else if level=1 then exp="Low";

else if level = 2 or 3 then exp="Medium";

else  exp="High";

run;

 

Which of the following is correct

 

A)Low,Medium,High

B)Low,Medium,High,Unknown

C)Low,Medium,High,Unknown and high

D)Low,Medium,High,Unknown, high, and (missing character values)

 

Answer : B

 

Could someone please suggest why it is B not C.. Many thanks in advance.


 

rajeshalwayswel
Pyrite | Level 9

 

  @reeza if you don't want to answer please won't reply to the question someone 
will answer in a hurry I didn't check the code. This is my code
data have; input name $ level; cards; Frank 1 Joan 2 Sui 2 Jose 3 Burt 4 Kelly . Juan 1 ; run; data want; set have; if level=. then exp="unknown"; else if level=1 then exp="Low"; else if level = 2 or 3 then exp="Medium"; else exp="High"; run;
Astounding
PROC Star

Even with this correction, you have errors in the program that make it difficult to figure out what you are looking for.

 

You can get "unknown" but you can't get "Unknown" because that doesn't exist in your program.

 

You can get "High" but you can't get "high" because that doesn't exist in your program.

 

The way you typed the program, you would actually get:

 

"unknown", "Low" and "Medium" which is not one of the choices you presented.  You can see that easily enough by testing your own program.  Type in the question correctly, and you can get a better answer.

Reeza
Super User

I'm happy to answer, but you do have to ask a question. Where in your post is a question? You have the multiple choice answers but no actual question posted. 

 

Exact Question:

https://communities.sas.com/t5/SAS-Programming/IF-ELSE-IF-CONDITION/m-p/497308/highlight/true#M13176...

 

I can only respond to what I see posted, the code is incorrect and would not run, not sure why it's a problem to say that when it's clearly true. How am I supposed to know if that's part of the question or if it's a mistake you made? I can only see what you've posted. 

 

https://communities.sas.com/t5/SAS-Support-Communities/How-to-ask-a-good-question-and-receive-a-fast...


@rajeshalwayswel wrote:

 

  @reeza if you don't want to answer please won't reply to the question someone 
will answer in a hurry I didn't check the code. This is my code

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 922 views
  • 2 likes
  • 4 in conversation