BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasuser77
Calcite | Level 5

Hi,

I've a dataset similar to below. I want to assign the Group by value to individual records as shown below.

 

NameSex
AliceF
Barbara 
Carol 
Jane 
Janet 
Joyce 
Judy 
Louise 
Mary 
AlfredM
Henry 
James 
Jeffrey 
John 
Philip 
Robert 
Ronald 
Thomas 
William

 

 

desired output

 

NameSex
AliceF
BarbaraF
CarolF
JaneF
JanetF
JoyceF
JudyF
LouiseF
MaryF
AlfredM
HenryM
JamesM
JeffreyM
JohnM
PhilipM
RobertM
RonaldM
ThomasM
WilliamM
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
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;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20
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;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

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!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 958 views
  • 0 likes
  • 2 in conversation