Hi,
I've a dataset similar to below. I want to assign the Group by value to individual records as shown below.
Name | Sex |
Alice | F |
Barbara | |
Carol | |
Jane | |
Janet | |
Joyce | |
Judy | |
Louise | |
Mary | |
Alfred | M |
Henry | |
James | |
Jeffrey | |
John | |
Philip | |
Robert | |
Ronald | |
Thomas | |
William |
|
desired output
Name | Sex |
Alice | F |
Barbara | F |
Carol | F |
Jane | F |
Janet | F |
Joyce | F |
Judy | F |
Louise | F |
Mary | F |
Alfred | M |
Henry | M |
James | M |
Jeffrey | M |
John | M |
Philip | M |
Robert | M |
Ronald | M |
Thomas | M |
William | M |
data have;
infile cards truncover;
input (Name Sex) ($);
cards;
Alice F
Barbara
Carol
Jane
Janet
Joyce
Judy
Louise
Mary
Alfred M
Henry
James
Jeffrey
John
Philip
Robert
Ronald
Thomas
William
;
data want;
set have;
retain _s;
if missing(sex) then sex=_s;
else _s=sex;
drop _s;
run;
data have;
infile cards truncover;
input (Name Sex) ($);
cards;
Alice F
Barbara
Carol
Jane
Janet
Joyce
Judy
Louise
Mary
Alfred M
Henry
James
Jeffrey
John
Philip
Robert
Ronald
Thomas
William
;
data want;
set have;
retain _s;
if missing(sex) then sex=_s;
else _s=sex;
drop _s;
run;
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!
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.