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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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