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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.