BookmarkSubscribeRSS Feed
Jianan_luna
Obsidian | Level 7

When I was doing sample exam question of base certification, I am confused about one question. The question is following, and I change the code and run it, but I got different answer for second question. Can you please help me figure it out? Thanks so much!

Jianan_luna_0-1597275406562.png

 

data work.lowchol work.highchol  work.misschol;
 	set sashelp.heart;
 if cholesterol lt 200 then output work.lowchol;
 if cholesterol ge 200 then output work.highchol;
 if cholesterol ne '.' then output work.misschol;
run;

proc contents data=work.highchol;
run;

proc contents data=work.lowchol;
run;
3 REPLIES 3
ballardw
Super User

Did you intend to use

 if cholesterol ne '.' then output work.misschol;

for "if cholesterol is not missing"? That is what the above does.

Cynthia_sas
SAS Super FREQ

Hi:

  There are syntax errors and logic errors in the program. Did you fix those errors? The answers given at the bottom of your screen shot are correct. When I run the program, after fixing the issues, here's what I see:

Cynthia_sas_0-1597278368031.png

 

  So I do find 1405 rows with low cholesterol and 3652 with high cholesterol and 152 have cholesterol values missing. Remember that missing values for numeric variables are tested using a . (not a quoted '.' as shown in the program). So one place to start would be to get rid of this NOTE that you might be seeing if you submit the original program unchanged:

Cynthia_sas_1-1597278544449.png

There are 2 problems with the above IF statement -- the dot (.) for missing should NOT be quoted and the NE means "not equal". However, to write to work.misschol you need to test whether the value for cholesterol EQ (or equal to) . or missing.

 

  The other issue is that IF you leave the test for missing at the bottom of the 3 IF statements, then the missing will also get output to the LOWCHOL data set and you'll have the wrong number of obs, as shown below:

Cynthia_sas_2-1597278786696.png

 

  So now you've got to fix the logic problem involving the IF statements. There are a few different ways to do that. Here are two of them:

Cynthia_sas_3-1597279080331.png

 

  I'd recommend going back and review the material on IF statements in the Programming 1 and Programming 2 classes to help you understand why this program didn't work initially and how you needed to fix it to get the right answers.

 

Cynthia

 

 

 

Kurt_Bremser
Super User

A missing value is smaller than anything (by definition), so these values are included in the lowchol dataset also. You need to do a semantic change with your statements.

Welcome to the Certification Community

 

This is a knowledge-sharing community for SAS Certified Professionals and anyone who wants to learn more about becoming SAS Certified. Ask questions and get answers fast. Share with others who are interested in certification and who are studying for certifications.To get the most from your community experience, use these getting-started resources:

Community Do's and Don'ts
How to add SAS syntax to your post
How to get fast, helpful answers

 

Why Get SAS Certified.jpg

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 932 views
  • 0 likes
  • 4 in conversation