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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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