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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—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
  • 5 replies
  • 1646 views
  • 3 likes
  • 3 in conversation