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

Hi I have a data like this:

data have;

input ID EventID Male $ Female $ MTF $ FTM $;

datalines;

1 1 male

1 2 

1 3 male

2 1    female

2 2    female

2 3 

3 1          mtf

3 2         

3 3        Mtf

run;

 I want it to be:

1 1 male

1 2  male

1 3 male

2 1    female

2 2    female

2 3    female

3 1          mtf

3 2          mtf

3 3         mtf

data want;
do until(last.Ieventid);
set have;
length m $4;
length f $6;
length mtf $14;
length ftm $14;
by eventid;
M=Catx('' , Male);
F=Catx('' , Female);
mtf=Catx('' , mtf);
end;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
input ID EventID Male $ Female $ MTF $ FTM $;
datalines;
1 1 male . . .
1 2 . . . .
1 3 male . . .
2 1   . female . .
2 2   . female . .
2 3  . . . .
3 1  . .        mtf .
3 2  . . . .       
3 3  . .      mtf .
;
run;
data want;
 update have(obs=0) have;
 by id;
 output;
run;

View solution in original post

3 REPLIES 3
mkeintz
PROC Star

Please provide your HAVE dataset in a working data step.  Otherwise we are left to guess what your data really look like.

 

And provide a working WANT data step as well.

 

Help us help you.

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Ksharp
Super User
data have;
input ID EventID Male $ Female $ MTF $ FTM $;
datalines;
1 1 male . . .
1 2 . . . .
1 3 male . . .
2 1   . female . .
2 2   . female . .
2 3  . . . .
3 1  . .        mtf .
3 2  . . . .       
3 3  . .      mtf .
;
run;
data want;
 update have(obs=0) have;
 by id;
 output;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1017 views
  • 0 likes
  • 3 in conversation