BookmarkSubscribeRSS Feed
PriyaB
Fluorite | Level 6

For the below project3 I have tried to fix the errors and write code by my understanding but after running my code for question 5 I got the exact answer mentioned but for question no. 6 I m getting value as 1557 instead of 1405 which is the correct answer. So can anyone please see my coding and let me know where I am lacking. that would be really helpful. Thanks in advance.

 

PriyaB_0-1714022482023.png

 

* Here is my code :

 

data work.lowchol work.highchol work.misschol;
	set sashelp.heart;

	if cholesterol lt 200 then
		do;
			lowchol="low";
			output lowchol;
		end;
	else if cholesterol ge 200 then
		do;
			highchol="high";
			output highchol;
		end;
	else if cholesterol=. then
		do;
			misschol="miss";
			output misschol;
		end;
run;
2 REPLIES 2
Astounding
PROC Star
When you test for cholesterol lt 200, that comparison includes missing values. There are several ways to fix this. One possibility is checking for missing values first, then using "else" to check for lt 200.
ballardw
Super User

MISSING value is always LESS THAN any given value. So part of the program logic that needs adjustment is order of comparison. If you look in LOWCHOL data set you should find all of the missing cholesterol values as well as the non-missing less than 200.

 

Hint: SHOW your log, copy the log text with code and all the notes. Copy the text, on the forum open a text box using the </> icon that appears above the message window and paste the text. The text box will preserve the formatting of any diagnostic messages that SAS often provides while the main message windows on this forum will reformat pasted text.

 

Then ask about the problem with what your result was. Like, why does my Lowchol data set have more than 1405 observations?

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 710 views
  • 2 likes
  • 3 in conversation