BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
desireatem
Pyrite | Level 9

id gap
001 0
001 1
001 2
002 0
002 2
002 1
003 0
003 1
003 1
004 0
004 2
004 2
005 0
;

Once gap is a 1 in any position for a particular id, gap=1 for all visit for that particular id.

if gap is 0, 2, without one, then for that id gap=2 for both position ie, we change the 0 to 2.

that above data will Change to:

id gap
001 1
001 1
001 1
002 1
002 1
002 1
003 1
003 1
003 1
004 2
004 2
004 2
005 0
;

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

This probably comes close enough:

 

data want;

do until (last.id);

   set have;

   by id;

   if gap=1 then new_gap=1;

   else if gap=2 and new_gap=. then new_gap=2;

end;

do until (last.id);

   set have;

   by id;

   if new_gap > . then gap = new_gap;

   output;

end;

drop new_gap;

run;

 

When I say comes "close enough", the program doesn't check for 0 and 2.  It checks for 2 (but without 1).

 

The top loop reads all the observations for an ID, looking at the GAP values.  Then the bottom loop re-reads the same observations, changes GAP, and outputs.

View solution in original post

2 REPLIES 2
Astounding
PROC Star

This probably comes close enough:

 

data want;

do until (last.id);

   set have;

   by id;

   if gap=1 then new_gap=1;

   else if gap=2 and new_gap=. then new_gap=2;

end;

do until (last.id);

   set have;

   by id;

   if new_gap > . then gap = new_gap;

   output;

end;

drop new_gap;

run;

 

When I say comes "close enough", the program doesn't check for 0 and 2.  It checks for 2 (but without 1).

 

The top loop reads all the observations for an ID, looking at the GAP values.  Then the bottom loop re-reads the same observations, changes GAP, and outputs.

desireatem
Pyrite | Level 9

Thank you very much!!!!

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!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 698 views
  • 0 likes
  • 2 in conversation