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;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.