SIM2000
SIM2000

Reputation: 33

SAS Fill In Blanks With Retain Statement

So I am trying to retain values on SAS but with a condition that includes my ID field. I have the following dataset:

ID Amount
1 230
1 450
1 .
1 .
2 .
2 .

I want to retain provided the ID is the same and zero if its a dot, see results below:

ID Amount
1 230
1 450
1 450
1 450
2 0
2 0

Upvotes: 1

Views: 478

Answers (1)

data _null_
data _null_

Reputation: 9109

How about the UPDATE trick.

data test;
   infile cards expandtabs;
   input id amount;
   cards;
1   230
1   450
1   .
1   .
2   .
2   .
;;;;
   run;
proc print;
   run;
data test2;
   update test(obs=0) test;
   by id;
   if first.id and missing(amount) then amount=0;
   output;
   run;
proc print;
   run;

enter image description here

Upvotes: 1

Related Questions