Help using Base SAS procedures

how to fix missing IDs

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 128
Accepted Solution

how to fix missing IDs

This dataset was imported from an excel file.

raw SAS dataset as the follows:

ID    v1   v2

12    2    3

.     3    4

.     8    9

41   2    3

.     3    4

.     8    9

.     3    4

.     8    9

14    2    3

.     3    4

.     8    9

data wanted:

ID    v1   v2

12    2    3

12    3    4

12    8    9

41    2    3

41    3    4

41    8    9

41    3    4

41    8    9

14    2    3

14    3    4

14    8    9

Any easier way to do this ? thanks


Accepted Solutions
Solution
‎10-30-2012 02:30 PM
Super User
Posts: 5,516

Re: how to fix missing IDs

One way:

data want;

   set have;

   retain new_id;

   if id ne . then new_id=id;

   drop id;

   rename new_id=id;

run;

Good luck.

View solution in original post


All Replies
Solution
‎10-30-2012 02:30 PM
Super User
Posts: 5,516

Re: how to fix missing IDs

One way:

data want;

   set have;

   retain new_id;

   if id ne . then new_id=id;

   drop id;

   rename new_id=id;

run;

Good luck.

Frequent Contributor
Posts: 128

Re: how to fix missing IDs

Posted in reply to Astounding

Thanks Astounding. :smileylaugh:

Respected Advisor
Posts: 3,799

Re: how to fix missing IDs

This is basically an LOCF problem and if you have more that a couple of variables that need to be carried forward you might find this helpful.

data missid;
   input ID v1 v2;
   retain dummy 1;
  
cards;
12    2    3
.     3    4
.     8    9
41   2    3
.     3    4
.     8    9
.     3    4
.     8    9
14    2    3
.     3    4
.     8    9
;;;;
   run;
data fillid(drop=dummy);
   update missid(obs=0) missid;
   by dummy;
   output;
  
call missing(of v1-v2);
   run;
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 183 views
  • 2 likes
  • 3 in conversation