BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
sas51
Fluorite | Level 6
Hi all,
I have an array of variables, i.e. Age1, Age2 ... Age144 (numeric) a MEMBERNM (character) and a family name variable FAMILYNM (character).

The age has 144 fields because it represents 144 yearly positions captured.

The data looks something like this
FAMILYNM MEMBERNM AGE1 AGE2 ...
SMITH JOHN 1 2 ...
SMITH MARY 5 6 ...
SWIFT TAYLOR 4 5 ...
SWIFT MEGAN 1 2

I would like to create an array of variables (MAXAGE1 MAXAGE2 ... MAXAGE144) which gives me the maximum age of every family, hence output should be,
FAMILYNM MEMBERNM AGE1 AGE2 ... MAXAGE1 MAXAGE2 ...
SMITH JOHN 1 2 ... 5 6
SMITH MARY 5 6 ... 5 6
SWIFT TAYLOR 4 5 ... 4 5
SWIFT MEGAN 1 2 ... 4 5

Appreciate the kind assistance.

1 ACCEPTED SOLUTION

Accepted Solutions
s_lassen
Meteorite | Level 14

Something like this, I suppose:

Data want;                                                                                                                              
  do until(last.familynm);                                                                                                              
    set have;                                                                                                                           
    by familynm;                                                                                                                        
    array ages(*) age1-age144;                                                                                                          
    array maxage(*) 8 maxage1-maxage144;                                                                                                
    do _N_=1 to dim(ages);                                                                                                              
      maxage(_N_)=max(maxage(_N_),ages(_N_));                                                                                           
      end;                                                                                                                              
    end;                                                                                                                                
  do until(last.familynm);                                                                                                              
    set have;                                                                                                                           
    by familynm;                                                                                                                        
    output;                                                                                                                             
    end;                                                                                                                                
run;         

View solution in original post

2 REPLIES 2
s_lassen
Meteorite | Level 14

Something like this, I suppose:

Data want;                                                                                                                              
  do until(last.familynm);                                                                                                              
    set have;                                                                                                                           
    by familynm;                                                                                                                        
    array ages(*) age1-age144;                                                                                                          
    array maxage(*) 8 maxage1-maxage144;                                                                                                
    do _N_=1 to dim(ages);                                                                                                              
      maxage(_N_)=max(maxage(_N_),ages(_N_));                                                                                           
      end;                                                                                                                              
    end;                                                                                                                                
  do until(last.familynm);                                                                                                              
    set have;                                                                                                                           
    by familynm;                                                                                                                        
    output;                                                                                                                             
    end;                                                                                                                                
run;         
ballardw
Super User

This seems like you may be attempting to force a spreadsheet style of solution onto a SAS data set.

How do you expect to use that result?

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
  • 588 views
  • 0 likes
  • 3 in conversation