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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: