Help using Base SAS procedures

sas query

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 145
Accepted Solution

sas query

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


Accepted Solutions
Solution
‎05-20-2015 09:49 AM
Super Contributor
Posts: 275

Re: sas query

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


All Replies
Solution
‎05-20-2015 09:49 AM
Super Contributor
Posts: 275

Re: sas query

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;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 192 views
  • 0 likes
  • 2 in conversation