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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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 save with the early bird rate—just $795!
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.