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

I have a dataset with variables ID VISITNUM VISIT DATE,

I should write query in such a way that, for every id the difference between two successive visits should not be more than 6 weeks. If it is more than 6 weeks I should output those discrepancies. I am attaching sample data.

100010001           1              CYCLE 1 2014-09-15

100010001           2              CYCLE 2 2014-10-27

100010001           3              CYCLE 3 2014-11-27

100010002           1              CYCLE 1 2014-10-13

100010002           2              CYCLE 2 2014-11-24

100010003           1              CYCLE 1 2015-02-08

100010003           1              CYCLE 1 2015-04-08

100010004           1              CYCLE 1 2015-04-28

100020001           1              CYCLE 1 2014-12-04

100020001           2              CYCLE 2 2015-01-15

100020001           3              CYCLE 3 2015-03-02

100020001           4              CYCLE 4 2015-04-13

100020002           1              CYCLE 1 2015-03-18

100020002           2              CYCLE 2 2015-04-29

100030002           1              CYCLE 1 2014-11-03

100030002           2              CYCLE 2 2014-12-22

100030002           3              CYCLE 3 2015-02-09

100030002           4              CYCLE 4 2015-03-23

100030003           1              CYCLE 1 2015-05-04

140010004           1              CYCLE 1 2015-02-11

140010004           2              CYCLE 2 2015-03-27

1 ACCEPTED SOLUTION

Accepted Solutions
slchen
Lapis Lazuli | Level 10

data have;

input id $10. visit cycle $ date  yymmdd10.;

format date yymmdd10. ;

cards;

100010001           1              CYCLE-1 2014-09-15

100010001           2              CYCLE-2 2014-10-27

100010001           3              CYCLE-3 2014-11-27

100010002           1              CYCLE-1 2014-10-13

100010002           2              CYCLE-2 2014-11-24

100010003           1              CYCLE-1 2015-02-08

100010003           1              CYCLE-1 2015-04-08

100010004           1              CYCLE-1 2015-04-28

100020001           1              CYCLE-1 2014-12-04

100020001           2              CYCLE-2 2015-01-15

100020001           3              CYCLE-3 2015-03-02

100020001           4              CYCLE-4 2015-04-13

100020002           1              CYCLE-1 2015-03-18

100020002           2              CYCLE-2 2015-04-29

100030002           1              CYCLE-1 2014-11-03

100030002           2              CYCLE-2 2014-12-22

100030002           3              CYCLE-3 2015-02-09

100030002           4              CYCLE-4 2015-03-23

100030003           1              CYCLE-1 2015-05-04

140010004           1              CYCLE-1 2015-02-11

140010004           2              CYCLE-2 2015-03-27

;

run;

proc sql;

   select b.*,ifn(intck('week',a.date,b.date)>6,1,0) as flag from have a right join have b

   on a.id=b.id and b.visit-a.visit=1 order by id,visit;

quit;

View solution in original post

1 REPLY 1
slchen
Lapis Lazuli | Level 10

data have;

input id $10. visit cycle $ date  yymmdd10.;

format date yymmdd10. ;

cards;

100010001           1              CYCLE-1 2014-09-15

100010001           2              CYCLE-2 2014-10-27

100010001           3              CYCLE-3 2014-11-27

100010002           1              CYCLE-1 2014-10-13

100010002           2              CYCLE-2 2014-11-24

100010003           1              CYCLE-1 2015-02-08

100010003           1              CYCLE-1 2015-04-08

100010004           1              CYCLE-1 2015-04-28

100020001           1              CYCLE-1 2014-12-04

100020001           2              CYCLE-2 2015-01-15

100020001           3              CYCLE-3 2015-03-02

100020001           4              CYCLE-4 2015-04-13

100020002           1              CYCLE-1 2015-03-18

100020002           2              CYCLE-2 2015-04-29

100030002           1              CYCLE-1 2014-11-03

100030002           2              CYCLE-2 2014-12-22

100030002           3              CYCLE-3 2015-02-09

100030002           4              CYCLE-4 2015-03-23

100030003           1              CYCLE-1 2015-05-04

140010004           1              CYCLE-1 2015-02-11

140010004           2              CYCLE-2 2015-03-27

;

run;

proc sql;

   select b.*,ifn(intck('week',a.date,b.date)>6,1,0) as flag from have a right join have b

   on a.id=b.id and b.visit-a.visit=1 order by id,visit;

quit;

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
  • 1 reply
  • 701 views
  • 0 likes
  • 2 in conversation