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

Hello,

I'm preparing for SAS base certification and I require some clarification regarding the below question.

Data Step

Data work.Test;

Infile ‘c:\class1.csv’ dsd;

Input Name $ Sex $ Age Height;

If Age NE 16 and Age NE 15 then Group = 1;

Else Group = 2;

Q Which of the following assignment statements for variable group are functionally equivalent to the original statement used in the above data step?

Below are 2 of the answers give. The correct answer is answer B. I understand why answer B is correct. However can someone please explain why answer A is wrong? My argument is a person can't have 2 age values, therefore answer A should work too.

     A) if (Age NE 16) or (Age NE 15) then Group=1; else Group=2;

     B) if Age not in(15,16) then Group=1; else Group=2

Any help regarding this is appreciated. Thank you in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Ah yes.  Its actually so subtle I didn't see it on a first read through.  They have switched the logic gate in A:

If Age=16, then the logic:

(age ne 16)=0, (age ne 15)=1 therefore 0 or 1 =1

If age=15 then:

(age ne 16)=1, (age ne 15)=0 therefore 1 or 0 =1

In the original code:

If Age=16, then the logic:

age ne 16=0, age ne 1=1 therefore 0 and 1 =0

If age=15 then:

age ne 16=1, age ne 15=0 therefore 1 and 0 =0

You see the switch from the and to the or reverses the result.

Plus the fact that in() reads easier and is expandable.  And the original is two tests, the in() is one.

View solution in original post

4 REPLIES 4
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Ah yes.  Its actually so subtle I didn't see it on a first read through.  They have switched the logic gate in A:

If Age=16, then the logic:

(age ne 16)=0, (age ne 15)=1 therefore 0 or 1 =1

If age=15 then:

(age ne 16)=1, (age ne 15)=0 therefore 1 or 0 =1

In the original code:

If Age=16, then the logic:

age ne 16=0, age ne 1=1 therefore 0 and 1 =0

If age=15 then:

age ne 16=1, age ne 15=0 therefore 1 and 0 =0

You see the switch from the and to the or reverses the result.

Plus the fact that in() reads easier and is expandable.  And the original is two tests, the in() is one.

Ksharp
Super User

Simple Q:

it should be

if (Age NE 16) and (Age NE 15) then Group=1; else Group=2;


if age=15  or if age=16

the condition :"(Age NE 16) or (Age NE 15) " will be true .





Xia Keshan

Kurt_Bremser
Super User

A) if (Age NE 16) or (Age NE 15)

is always true. If a person's age is 15, the first half is true, if 16, the second half is true, and with all other ages both parts are true. group will always be set to 1.

YasodaJ
Calcite | Level 5

Thank you very much for the prompt replies Smiley Happy

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 3457 views
  • 4 likes
  • 4 in conversation