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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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