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

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.

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