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

I'm in bit of a pickle here and turning to you all for help. I'm a SAS beginner so pardon me if this is a very basic question. Basically, I have this dataset:

 

ID  Gender  Type

1    F            X

      F            Y

2    F            Y

      M           Y

      F            X

 

Both the first two observations "belong" to ID=1 and the last three observations "belong" to ID=2. How do I fill in the missing ID values? I've tried using retain but SAS won't let me run any data step where I have a "by id" statement because this dataset isn't sorted by id. However, I can't sort it by ID because then I lose the grouping.

 

Any solutions here?

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

 

data want;

set have;

retain _id;

if not missing(id) then _id=id;

else id=_id;

drop _id;

run;

 

 

View solution in original post

1 REPLY 1
novinosrin
Tourmaline | Level 20

 

data want;

set have;

retain _id;

if not missing(id) then _id=id;

else id=_id;

drop _id;

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
  • 1 reply
  • 836 views
  • 0 likes
  • 2 in conversation