BookmarkSubscribeRSS Feed
silasskovsbo
Calcite | Level 5

I have a data set(call DATASET) as this (about 100000 observations):

XYZ
aj0
bk1
cl0
dm0
eo1
fp0
gq0
hr0
is1

I would like to do is to add one blank row above each row where Z=1.

to get this data set

XYZ
aj0
bk1
cl0
dm0
eo1
fp0
gq0
hr0
is1

Can anybody help and I would be very thankfull.

Best Silas, London

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

Please try,

data have;

  infile cards truncover;

  input x :$1. y:$1. z;

cards;

a    j    0

b    k    1

c    l    0

d    m    0

e    o    1

f    p    0

g    q    0

h    r    0

i    s    1

;

proc sort data=have;

  by x y;

run;

data want;

  set have;

  output;

by x y;

if z=1 then output;

run;

data want_;

  set want;

  by x y;

  if first.x and z=1 then call missing(x,y,z);

run;

Thanks,

Jag

Thanks,
Jag
pradeepalankar
Obsidian | Level 7

data have;

input x $ y $ z;

id+1;

cards;

a j 0

b k 1

c l 0

d m 0

e o 1

f p 0

g q 0

h r 0

i s 1

;

proc sort data=have;by descending id;run;

data have;

set have(drop=id);

if z=1 then do; idnew+1;output;

call missing(x,y,z);end;

else;idnew+1;output;

run;

proc sort data=have out=want(drop=idnew);by descending idnew;

run;

Haikuo
Onyx | Level 15

A typical look-ahead:

data have;

  infile cards truncover;

  input x :$1. y:$1. z;

cards;

a    j    0

b    k    1

c    l    0

d    m    0

e    o    1

f    p    0

g    q    0

h    r    0

i    s    1

;

data want;

  set have;

  set have(firstobs=2 rename=(z=_z) keep=z) have (obs=1 drop=_all_);

  output;

if _z=1 then do; call missing (of _all_); output;end;

drop _z;

run;

Haikuo

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
  • 1524 views
  • 0 likes
  • 4 in conversation