Question about RETAIN statement.

Reply
New User
Posts: 1

Question about RETAIN statement.

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

Valued Guide
Posts: 597

Re: Question about RETAIN statement.

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
Super User
Posts: 6,785

Re: Question about RETAIN statement.

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?

Super User
Posts: 23,771

Re: Question about RETAIN statement.

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


 

Super User
Posts: 13,581

Re: Question about RETAIN statement.

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.

 

 

Super User
Posts: 23,771

Re: Question about RETAIN statement.

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

Ask a Question
Discussion stats
  • 5 replies
  • 165 views
  • 3 likes
  • 5 in conversation