Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- Programming
- /
- Difference between using If versus where

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

☑ This topic is **solved**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 12-02-2022 12:54 PM
(869 views)

Hi,

I took the SAS 9.4 Base Certification practice exam. Below are the steps for question 13.

This project will use data set **cert.input36**. At any time, you may save your program as **program36** in **cert\programs**.

Write a SAS program that will clean the data in **cert.input36** as follows:

- 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.

How many observations are in **results.output36**?

The original dataset had 5000 observations.

My answer was 4897 observations.

The practice exam has 4992 observations for the answer.

I can't figure out why there is a 95 observation difference.

I did answer the second question regarding the median correctly.

Thanks for your help.

I used the following code:

data cleandata36;

set cert.input36;

group = upcase(group);

where group in ('A' 'B');

run;

proc means data=cleandata36 median maxdec=0;

class group;

var kilograms;

run;

data results.output36;

set cleandata36;

if Group = 'A' and kilograms lt 40 or kilograms gt 200 then kilograms = 79;

if Group = 'B' and kilograms lt 40 or kilograms gt 200 then kilograms = 89;

run;

proc means data=results.output36 maxdec= 2 min max mean median n;

class group;

var kilograms;

run;

The answer code is:

data work.cleandata36;

set cert.input36; group=upcase(group);

if group in ('A','B');

run;

proc means data=work.cleandata36 median; class group; var kilograms; run; data results.output36; set cleandata36; if Kilograms < 40 or Kilograms > 200 then do; if group='A' then kilograms=79; else kilograms=89; end; run; proc contents data=results.output36;

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Here is a small example of what the difference is:

data example; input group $; datalines; a A b B ; data usewhere; set example; group=upcase(group); where group in ('A' 'B'); run; data useif; set example; group=upcase(group); if group in ('A' 'B'); run;

WHERE used the values from in input data set vector, the "upcase" is basically ignored at it would be applied after the selection.

IF uses the values of the variable as encountered.

So your code did not select the values of group from 'a' and 'b' that should be converted to 'A' and 'B' resulting in fewer observations.

8 REPLIES 8

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Here is a small example of what the difference is:

data example; input group $; datalines; a A b B ; data usewhere; set example; group=upcase(group); where group in ('A' 'B'); run; data useif; set example; group=upcase(group); if group in ('A' 'B'); run;

WHERE used the values from in input data set vector, the "upcase" is basically ignored at it would be applied after the selection.

IF uses the values of the variable as encountered.

So your code did not select the values of group from 'a' and 'b' that should be converted to 'A' and 'B' resulting in fewer observations.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thanks for the great explanation.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

and the example. I ran the code and it helps me to see it on my own.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

The output values of median we are getting are as follows :

for group 'A' median=79,

for group 'B' median=89,

but when using this values as answer to questions in SAS practice test available on SAS website it shows as wrong answer.

Correct answer shown there are

for group 'A' median=76.3

for group 'B' median=86.5

Can anyone please confirm what are the correct answers.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@Mansi24 wrote:

The output values of median we are getting are as follows :

for group 'A' median=79,

for group 'B' median=89,

but when using this values as answer to questions in SAS practice test available on SAS website it shows as wrong answer.

Correct answer shown there are

for group 'A' median=76.3

for group 'B' median=86.5

Can anyone please confirm what are the correct answers.

No one knows what this means. You have given us no context and tried to ask in an old thread which is unrelated to your question. Please start a new thread, people will be happy to help you in a new thread. Please make sure you provide all necessary background and context to your question.

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

@Mansi24 wrote:

The output values of median we are getting are as follows :

for group 'A' median=79,

for group 'B' median=89,

but when using this values as answer to questions in SAS practice test available on SAS website it shows as wrong answer.

Correct answer shown there are

for group 'A' median=76.3

for group 'B' median=86.5

Can anyone please confirm what are the correct answers.

Without data and the actual code run there is no way to answer you question.

Since you say this on the SAS website then post the link to the page with the DATA and then show us the code you ran against that data set.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

The difference is like the difference between the bouncer at the door of Studio 54 and host at a restaurant.

The bouncer (the WHERE) prevents you from entering the building and the host (subsetting IF) prevents you from getting to a table.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

What a great way to remember!

thanks.

Diane

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. **Registration is now open through August 30th**. Visit the SAS Hackathon homepage.

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.