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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 971 views
  • 0 likes
  • 2 in conversation