BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
mbayer
Calcite | Level 5

data example;
input $record_id education mother;
datalines;
1 2 1
1 . 0
1 1 0
1 . 0
2 . 0
2 3 1
3 4 1
3 . 0
;
run;
*I want it to look like this;
data example;
input $record_id education mother;
datalines;
1 2 1
1 2 0
1 2 0
1 2 0
2 3 1
2 3 0
3 4 1
3 4 0
;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
5 REPLIES 5
mbayer
Calcite | Level 5

Close! I want the education value for the observations where mother = 1 to carry over for all the other observations with the same record _id. It isn't always the max value or the first value (within that record_id). 

Kurt_Bremser
Super User
data want;
do until (last.record_id);
  set have;
  by record_id;
  if mother = 1 then _ed = education;
end;
do until (last.record_id);
  set have;
  by record_id;
  education = _ed;
  output;
end;
drop _ed;
run;
SASKiwi
PROC Star

Here's an SQL-based approach:

data example;
input record_id $ education mother;
datalines;
1 2 1
1 . 0
1 1 0
1 . 0
2 . 0
2 3 1
3 4 1
3 . 0
;
run;

proc sql;
  create table want as
  select A.record_id
        ,B.education_max
	    ,A.mother
  from example as A
  left join
  (select record_id
         ,max(education) as education_max
   from example
   where mother = 1
   group by record_id
  ) as B
  on A.record_id = B.record_id
  ;
quit;

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