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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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