BookmarkSubscribeRSS Feed
Markanti
Calcite | Level 5
  1. What is the oldest mother (dmage) and what is the oldest father (dfage) in the Main SAS data set.  For father’s age, exclude age 99. (3 pts)



Unfinished Code

*HW 3 - Problem 2;

proc ;

run;  

 

finished code

data lab.oldest_ages;
set lab.main;
OldestMother = .;
OldestFather = .;
if dmage > OldestMother then
OldestMother = dmage;
if dfage < 99 ;
if OldestFather = . or dfage > OldestFather then
OldestFather = dfage;
where dmage ^= . and dfage ^= .;
run;
proc print data= lab.oldest_ages (firstobs = 1 obs=10);
var dmage dfage;
run;

2 REPLIES 2
Astounding
PROC Star

Since the "unfinished code" begins with the word PROC, it looks like you should use a SAS procedure, and not a DATA step.

 

Take a look at PROC MEANS.

 

You will need to run it twice (once for the fathers and once for the mothers), because excluding fathers age 99 might exclude an observation needed for processing the mothers.

Lukkul
Fluorite | Level 6

As @Astounding pointed correctly, you'd have to use procedure (as in the description of you homework 😉).

Although, the data step is incorrect anyway:

  • You don't retain the value of OldestMother and OlderstFather to next rows when processing. So when if statements are evaluated,  you're just comparing the values within the same row, you're not considering previous values of dmage, dfage (I'd suggest to play around with this a bit and see the numbers yourself).
  • There is no data structure provided in your question, so I'm only guessing the row consists of a couple, where in row you have age of mother and father. When you use if dfage < 99, you will exclude rows, and loose information on dmage

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 384 views
  • 1 like
  • 3 in conversation