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

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