BookmarkSubscribeRSS Feed
cperry16
Calcite | Level 5

Seeking help with a homework question:

 

Using the Blood dataset, drop WBC, RBC, and Subject and create a new dataset containing the observation with non-missing cholesterol (var name Chol). Use this dataset to create another dataset that contains the largest cholesterol value for each combination of gender, blood type, and age group. In the same DATA step, using the RETAIN statement, calculate the difference between the smallest and largest cholesterol for each combination of gender, blood type, and age group. Lable the new variables and print this dataset which should look like the following:

 

0418181532_HDR.jpg

5 REPLIES 5
SuryaKiran
Meteorite | Level 14

Don't let us do your homework. Try your best so that you can learn something while trying, lessons are always learned from mistakes. You may get answer if you post a question here directly, but if you try yourself that may lead you to learn some more new this you never came across. 

 

Try your best and if you don't get then come back with what you have tried and someone can help why your approach didn't workout.

Thanks,
Suryakiran
Astounding
PROC Star

While I agree that this is your homework not ours, I can give you a tiny bit of guidance.  All the homework questions depend on how much you already know.  So ...

 

How would you print the first 10 observations in the blood data set?

 

proc print data=????????? (obs=10);

run;

 

Do you know how to fill in the ??????????? to get the 10 observations to print?

Reeza
Super User

That's the wrong way to do it as well....

 

If you check PROC MEANS - the documentation has examples - use STACKODS option you can get the summaries and do the subtraction without RETAIN. 

 

https://github.com/statgeek/SAS-Tutorials/tree-save/master/proc_means_basic.sas

 


@cperry16 wrote:

Seeking help with a homework question:

 

Using the Blood dataset, drop WBC, RBC, and Subject and create a new dataset containing the observation with non-missing cholesterol (var name Chol). Use this dataset to create another dataset that contains the largest cholesterol value for each combination of gender, blood type, and age group. In the same DATA step, using the RETAIN statement, calculate the difference between the smallest and largest cholesterol for each combination of gender, blood type, and age group. Lable the new variables and print this dataset which should look like the following:

 

0418181532_HDR.jpg


 

ballardw
Super User

I sometimes get concerned that "homework" leads students to believe the exercise way is the best way to use SAS.

As @Reeza says this specific example would be more typically handled by Proc Means/Summary. As a 5 line program, including the Run; in the count.

I would hope the next bit the instructor covers is the equivalent Proc means/summary with the MAX and RANGE statistics and Class variables to show alternate (generally preferred) methods.

 

Or come up with a slightly more valid reason to use RETAIN.

 

 

Reeza
Super User

@ballardw I suspect its a professor using really really old course notes and methodologies. 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 5 replies
  • 897 views
  • 3 likes
  • 5 in conversation