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

I am having trouble understanding why " OR " is used instead of " AND " for Step 3.

 

The Question Asked:

    • Step 1:
      • create a temporary data set, cleandata36.
      • In this data set, convert all group values to upper case.
      • Then keep only observations with group equal to 'A' or 'B'.
    • Step 2:
      • Determine the MEDIAN value for the Kilograms variable for each group (A,B) in the cleandata36 data set. Round MEDIAN to the nearest whole number.
    • Step 3:
      • create results.output36 from cleandata36
      • Ensure that all values for variable Kilograms are between 40 and 200, inclusively.
      • If the value is missing or out of range, replace the value with the MEDIAN Kilograms value for the respective group (A,B) calculated in step 2.

 

Step 1: 
data work.cleandata36; set cert.input36; group=upcase(group); if upcase(group) in ('A','B'); run; Step 2:
proc means data=work.cleandata36 median; class group; var kilograms; run; Step 3:
data results.output36; set cleandata36; if Kilograms < 40 OR Kilograms > 200 then do; if group='A' then kilograms=79; else kilograms=89; end; run;
1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

You are relating to next statement:

if Kilograms < 40 OR Kilograms > 200 then do;

Remember that KILOGRAMS is just a variable and one value at a time.

None value can be <40 and >200 at the same time. but it can be

either <40 or >200 at this current observation. 

View solution in original post

2 REPLIES 2
Shmuel
Garnet | Level 18

You are relating to next statement:

if Kilograms < 40 OR Kilograms > 200 then do;

Remember that KILOGRAMS is just a variable and one value at a time.

None value can be <40 and >200 at the same time. but it can be

either <40 or >200 at this current observation. 

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
  • 2 replies
  • 2042 views
  • 3 likes
  • 3 in conversation