BookmarkSubscribeRSS Feed
HDSimo
Calcite | Level 5
Hi ,
i have a dataset with variable "a" that has 3 values: 0, 1, 2. I want to insert rows for the missing values in a dataset like this:

data a;
input a b;
cards ;
0 1
1 2
2 3
0 1
2 5
0 3
1 4
...
...
;
run;
i want my output will be like this :

0 1
1 2
2 3
0 1
1 .
2 5
0 3
1 4
2 .
Thank you very much in advance

Simone
3 REPLIES 3
HDSimo
Calcite | Level 5
My solution...

data new; retain i -1;
if i=2 then i=0; else i=i+1;
set a;
if i = a then output;
else do;
a=i; b=0;output;
end;
run;

Simone
HDSimo
Calcite | Level 5
Arghhh! It doesn't work?
Help please!
Patrick
Opal | Level 21
data Have;
input a b;
cards ;
0 1
1 2
2 3
0 1
2 5
1 1
2 1
1 3
;
run;

data want(keep=a b);
set have end=last;
retain counter 0 RetA RetB;
RetA=a;
RetB=b;
if counter>2 then counter=0;
do until( (counter>RetA and not last) or (last and counter>2));
if RetA=counter then
do;
a=RetA;
b=RetB;
end;
else
do;
a=counter;
call missing(b);
end;
output;
counter+1;
end;
run;

proc print data=want;
run;




HTH
Patrick

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

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1442 views
  • 0 likes
  • 2 in conversation