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

I have the below code.

 

proc sql;
	create table cares_count as
	select distinct a.pat_id, 1 as flag
	from fake_data a, fake_data b
	where a.pat_id = b.pat_id
		and b.visit_date > a.visit_date
		and intck('day', b.visit_date, a.visit_date) < 366;
quit;

Can you tell me what

b.visit_date > a.visit_date

is doing? I don't understand this line.

Here is some fake data.

data fake_data;
	input pat_id $	visit_date:MMDDYY10.;
	format visit_date MMDDYY10.;
	datalines;
12393	8/28/1982
12393	6/16/1993
12393	12/21/1982
12534	11/26/2010
12601	6/3/2021
12601	10/11/2015
12601	12/17/1983
12601	9/1/2019
12601	4/27/2000
12601	5/5/1986
12703	1/30/1987
12703	4/24/1988
12724	11/16/2021
12724	11/24/1985
12724	12/22/2016
12724	9/11/2014
12732	11/10/2016
12732	12/6/1986
12732	9/11/2001
12901	8/11/2019
13000	9/27/2007
13000	3/26/1987
13000	3/16/2011
13146	11/12/1991
13226	5/28/1983
13254	11/25/2022
13331	4/6/1996
13331	5/24/2020
13331	6/14/1985
13387	12/29/2009
13643	5/29/1985
13643	2/24/1985
13643	12/21/2018
14288	10/27/1987
14311	2/18/1984
14311	2/8/1996
14311	1/10/2023
14311	6/23/2013
14311	1/8/1996
14393	9/23/2017
14472	3/7/1997
14472	2/1/2005
14472	3/7/2001
15296	1/5/2016
15296	7/26/1992
15296	5/23/1983
15296	2/23/1983
15438	11/14/2013
15438	4/30/2003
15438	8/18/1995
15452	12/28/2022
15452	12/27/1996
15452	8/28/1992
15480	11/23/1988
15483	3/19/1999
15483	1/8/1999
15483	10/18/2001
15790	7/31/1984
15790	3/2/1984
15790	6/16/1983
15790	1/6/1993
15790	3/28/2011
15970	2/22/2003
16058	6/2/1985
16058	11/11/2009
16058	3/1/2013
16058	12/17/1982
16058	1/7/2005
16058	11/13/1999
16058	8/30/1990
16058	8/21/2019
16094	5/28/1983
16258	1/12/1985
16268	6/22/2007
16268	2/5/2017
16396	2/28/1994
16406	9/17/2013
16406	1/1/2007
16586	5/19/1989
16676	5/9/2015
16676	8/25/2018
16774	4/21/1992
16774	9/17/1983
17001	6/19/1997
17206	9/26/2001
17257	3/28/2013
17290	3/7/1987
17290	12/27/1995
17343	6/17/2021
17343	10/16/1988
17348	7/21/2011
17451	12/3/1991
17451	11/2/1989
17451	7/31/1989
17730	3/18/2022
18118	9/30/2002
18118	10/9/1986
18275	5/31/2004
18275	7/10/2016
18391	1/16/2017
18391	4/7/2017
18391	10/12/2003
18391	2/11/2015
18391	11/13/1994
18391	5/29/2009
18406	7/24/2004
18406	5/15/2017
18406	2/17/1987
18818	10/8/2001
19260	7/18/2008
19379	7/25/2019
19379	4/6/1988
19379	7/27/2006
19602	5/8/2004
19602	7/5/1984
19602	6/12/2003
19602	12/3/2021
19851	10/20/2017
19851	5/26/2009
19851	10/30/2021
19851	8/7/2018
20193	10/11/2008
20196	4/28/2007
20230	1/17/2021
20351	1/18/1999
20472	2/23/1993
20512	6/29/1985
20512	7/17/2000
20656	5/24/2008
20656	1/2/2002
20719	8/3/2012
20719	2/8/2005
20791	4/8/2018
20791	1/10/2014
20947	5/5/2020
20947	12/12/2013
20947	4/28/2002
20947	7/13/2002
21014	5/6/1986
21014	4/29/2017
21014	12/9/2020
21014	11/10/1984
21142	2/10/1999
21142	4/21/1991
21142	5/29/1997
21558	1/1/1991
21660	8/7/2021
21808	3/9/1998
22123	11/22/1989
22123	4/25/2013
22208	6/15/2011
22208	2/28/2007
22208	8/19/2002
22220	9/8/2002
22333	5/19/2000
22333	6/19/2003
22333	1/14/2007
22348	2/27/2010
22474	6/1/2017
22493	2/19/2019
22493	6/13/2003
22738	4/12/1994
22738	11/5/1994
22799	8/24/1995
22799	10/31/1989
22799	11/6/2022
22799	2/23/1993
22886	10/27/2018
22886	12/12/2002
22886	2/18/1989
22886	12/6/2012
22886	8/12/2018
22886	1/27/1988
22888	1/27/2021
22888	11/11/2009
22888	2/3/1989
22888	1/12/2005
23130	4/14/2013
23308	2/13/1994
23308	12/8/2017
23646	6/28/1987
23646	1/3/2002
23649	3/31/2012
23694	5/17/1982
23736	11/2/1989
24074	10/7/2022
24074	1/17/2023
24074	8/28/2005
24222	10/27/2013
24222	2/3/2021
24247	9/1/2017
24486	11/28/1988
24486	1/31/2008
24746	1/9/2008
24774	5/14/2021
24827	6/8/2015
24860	9/2/2004
24860	10/28/2000
25132	4/21/1990
25219	11/17/2001
25639	7/19/2014
25639	6/18/2006
25639	10/16/1984
25639	6/26/2015
25707	9/25/2015
25707	8/13/1995
25717	10/28/1997
25742	5/26/1995
25773	5/10/2016
25773	7/4/1986
25869	10/30/1997
25882	4/21/2018
25882	9/6/1984
25958	5/20/1993
25958	3/23/2007
25958	11/23/2021
25993	5/11/2003
26001	6/11/2002
26001	11/3/1983
26001	3/19/1991
26001	8/15/2010
26051	1/13/2017
26051	12/9/2017
26217	7/8/2014
26217	6/13/2001
26460	7/27/2011
26473	2/16/2013
26540	4/20/2000
26540	10/27/1993
26540	11/21/1989
26658	5/21/1986
26838	3/8/2004
26838	3/10/1997
26838	12/13/1988
26868	8/7/2005
26868	4/19/2006
26868	8/26/2020
27115	8/2/1983
27143	6/26/1992
27154	5/21/2006
27243	6/10/2016
27243	10/17/2011
27243	10/30/2001
27243	12/16/1999
27243	2/29/2000
27338	3/23/2000
27462	1/18/2010
27462	6/19/2002
27481	4/10/2003
27481	2/20/2000
27504	1/27/2021
27504	11/29/1987
27528	1/25/2010
27528	9/29/2022
27528	11/6/2000
27528	4/17/1984
27559	5/5/1988
27605	6/25/1997
27755	8/31/1990
27886	4/4/1985
27886	4/14/1991
27886	6/13/1989
27886	9/29/2010
27886	3/29/2017
27886	11/17/2004
28041	1/4/2004
28041	3/12/1988
28041	9/2/1985
28041	3/31/2013
28041	7/11/1985
28041	2/11/2017
28192	5/24/1982
28192	1/24/2009
28192	11/25/2011
28230	7/5/1999
28230	9/8/2015
28230	1/7/1984
28230	7/18/2014
28245	5/23/2012
28809	1/5/2009
28809	4/1/2020
28809	2/21/2015
28809	5/19/1987
28809	3/28/1996
28985	1/4/1986
28985	3/31/2013
28985	2/1/1987
28985	6/5/2013
28985	5/19/1986
29028	8/3/2018
29028	2/19/2014
29028	7/14/2019
29033	4/26/2000
29033	8/12/2021
29099	7/26/2007
29233	10/24/2009
29233	6/17/2000
29233	3/30/1986
29566	3/5/2007
29648	4/24/2002
30266	8/15/2002
30266	5/10/2021
30532	12/7/2000
30532	7/10/1982
30532	4/2/1985
30572	8/21/2004
30572	5/18/1999
30572	4/8/2019
30606	7/18/1994
30613	4/12/1990
30767	6/8/2003
30783	1/26/1994
30783	4/8/1998
30871	7/29/1988
30948	11/23/1993
31039	6/26/2014
31060	8/1/2000
31060	6/10/2014
31060	10/6/1988
31151	12/11/1991
31151	8/21/1991
31151	2/25/2023
31151	10/8/2011
31192	11/25/1988
31192	8/14/2003
31486	12/1/1994
31614	12/3/2019
31652	10/25/1999
31707	11/16/2012
31799	1/3/1995
31860	1/29/2009
32039	3/5/2009
32442	7/28/2011
32506	6/25/2005
32506	5/18/1986
32506	11/17/2017
32506	3/18/2011
32596	4/28/2015
32699	1/8/2017
32980	11/23/2009
32980	10/27/2021
32980	4/19/2002
33742	3/30/2005
33742	8/2/1982
33745	4/17/1993
33911	1/22/2023
33921	5/11/2022
34240	11/28/2013
34536	6/27/2007
34536	8/28/2000
34582	9/15/2003
34582	12/21/1994
34582	3/18/2016
34582	2/20/2023
34582	6/23/1998
34615	10/10/1995
34615	10/1/2010
34981	4/10/1992
34981	1/22/2010
35001	12/30/2001
35001	8/12/2020
35041	10/1/1984
35041	5/19/2022
35113	2/5/2002
35113	7/3/2004
35189	8/28/2009
35189	12/17/2003
35240	4/3/2013
35240	9/18/1996
35246	11/3/1984
35300	4/19/1988
35300	3/8/2016
35300	8/13/2012
35374	5/4/2000
35374	8/25/2018
35374	12/31/2004
35532	3/14/1994
35951	11/15/2005
35963	8/12/2006
35972	3/23/1998
35972	9/23/2017
36049	5/7/2013
36049	1/3/2013
36049	10/3/1994
36049	3/27/2003
36075	8/13/1993
36090	5/22/1995
36090	4/14/1995
36125	9/18/1989
36434	10/23/2017
36434	3/4/2001
36460	9/6/2004
36460	5/20/1993
36494	1/4/1990
36494	10/17/2008
36519	7/7/1996
36519	5/18/2019
36519	3/12/1996
36519	10/21/2008
36519	10/4/1989
36519	7/24/1987
36730	2/7/2011
36730	7/21/2021
36730	11/28/2004
36862	8/18/2003
36862	12/20/2017
36932	4/14/1994
37034	2/12/2013
37463	6/13/2009
37642	7/30/2018
37642	8/1/2001
37778	9/13/2002
37831	1/30/2009
37974	3/20/1989
37974	4/27/2018
37974	9/15/1998
38011	4/5/1992
38011	11/27/1988
38198	8/28/1994
38321	6/17/2017
38321	7/31/2003
38347	8/3/1985
38375	1/29/2023
38490	8/23/2003
38563	12/15/2008
38609	11/28/2022
38799	2/10/1992
38799	2/1/2019
38906	6/19/2006
38911	9/9/2018
38911	10/13/1982
38911	1/4/1985
39032	4/7/2022
39032	5/27/2008
39054	1/8/1992
39054	3/8/1992
39069	10/5/2021
39069	1/7/2002
39155	2/17/2013
39308	8/2/1989
39406	4/19/2011
39406	4/12/2009
39474	9/3/1996
40339	5/5/1986
40339	12/20/2009
40449	5/9/1984
40449	12/2/2016
40498	10/9/2011
40659	10/18/1987
41030	11/1/2011
41202	3/28/2002
41202	9/24/2016
41202	5/10/2014
41220	1/4/2005
41378	8/16/1989
41378	4/1/1986
41378	3/8/1995
41479	6/30/1996
41479	11/3/1985
41479	6/10/1998
41479	4/17/2014
41616	9/13/1993
41616	3/21/2004
41854	3/30/2008
41869	12/16/2013
41869	5/30/2010
41869	8/4/1993
41936	3/2/2017
42063	10/8/2008
42063	11/30/2000
42063	1/8/2008
42063	2/26/2017
42063	12/17/1989
42063	9/9/1995
42079	6/24/2011
42337	6/10/1986
42337	5/14/1987
42337	6/16/2010
42337	4/8/2002
42337	8/15/2006
42337	8/24/2009
42337	3/27/2006
42337	5/5/2015
42495	7/16/2008
42495	2/9/2009
42495	7/16/1983
42595	9/16/1989
42797	6/20/1997
42797	7/28/2000
42797	12/19/1982
42841	8/3/1991
42841	7/3/1997
42841	4/16/1984
43156	9/21/1990
43258	10/1/2004
43618	2/16/1988
43994	8/5/2003
44227	5/15/2014
44271	12/25/2021
44328	12/26/1995
44328	11/15/2010
44328	2/9/2002
44328	6/23/2003
44358	2/1/1993
44724	4/12/1986
45094	3/30/2005
45094	8/23/2010
45145	10/2/2015
45145	8/23/2018
45176	12/20/2013
45176	11/16/2000
45176	9/10/1984
45313	3/12/2021
45313	5/29/2011
45505	11/29/2006
45651	5/2/1986
45742	2/8/2014
45742	8/9/1991
45871	2/4/1994
45871	6/13/2007
45871	7/13/1982
45871	1/27/2019
45890	2/17/2001
45905	11/21/2000
46665	1/1/2021
46665	8/10/2000
46665	6/2/1986
46682	10/10/2009
46794	4/26/2010
46863	4/8/1992
46874	8/20/1999
46874	2/15/2012
46874	8/1/2016
47304	6/2/2003
47597	3/3/1983
47597	10/28/2001
47967	2/11/2015
47998	3/13/2016
48041	5/8/1996
48041	5/14/2008
48042	1/10/2019
48042	9/6/2005
48042	4/5/2004
48168	10/8/2008
48197	7/3/2021
48197	5/9/2016
48197	10/10/1983
48255	8/9/2018
48272	3/6/1985
48377	5/24/2001
48555	3/16/1999
48555	2/19/2011
48555	10/31/2018
48661	3/27/1990
48782	6/18/1994
48860	4/13/2018
48870	9/4/1989
48870	7/29/2012
48870	7/31/1998
48892	3/21/1987
48892	9/25/2002
48892	12/1/1985
48919	4/18/1982
48919	3/2/1992
48919	2/10/1993
49159	7/3/2019
49159	8/15/1982
49219	11/25/2018
49219	12/4/2000
49219	10/1/1986
49219	5/15/2000
49277	9/19/2016
49277	8/14/2003
49599	8/9/1990
49599	10/27/1998
49638	8/19/1991
49638	9/22/1982
49723	6/25/1991
49723	12/11/2019
49723	11/1/1993
49747	1/3/1990
49747	9/21/2017
49808	12/20/2022
49808	8/4/2012
49808	2/1/1986
49839	8/14/2006
49839	11/25/2009
49839	4/27/2021
49971	1/11/2015
49988	9/23/2011
50085	5/24/2009
50085	10/11/2001
50100	10/6/2005
50103	1/24/2013
50184	7/19/2005
50219	6/21/1991
50291	11/28/1988
50598	11/15/1996
50642	10/11/2013
50642	9/3/1998
50642	10/16/1985
50642	11/15/2013
50755	12/8/1994
50755	3/21/2007
50993	9/5/1999
50993	5/27/2014
51059	6/24/1986
51092	3/29/2010
51334	10/6/2005
51334	3/23/1992
51349	12/20/1997
51494	9/26/2011
51683	6/2/1994
51683	11/23/2002
51683	8/18/2006
51784	5/25/2018
51829	3/17/2015
52036	12/8/2005
52036	11/18/1994
52076	1/3/2011
52076	4/10/1987
52124	4/12/2020
52124	12/7/2000
52298	7/6/1998
52359	3/31/1989
52425	6/6/1999
52425	8/25/2003
52458	9/12/1995
53572	10/23/2021
53624	12/20/1989
53638	4/29/1991
53752	5/1/1999
53883	10/29/1996
53909	10/10/2004
53909	7/9/1985
54149	3/21/1983
54432	11/11/1987
54484	12/14/1992
54484	12/30/2003
54484	9/2/1998
54591	11/27/2019
54591	8/10/1992
54642	4/9/1998
54713	5/23/1985
54734	8/6/2003
54734	12/28/1993
54734	3/21/2010
54750	9/4/2014
54808	3/12/2001
54808	2/17/2007
54808	10/31/2011
54856	10/18/2022
54856	12/7/2020
54856	12/7/1982
54856	2/25/1990
54856	1/7/2014
54856	8/5/1987
54856	9/23/1995
54856	5/19/1999
54941	3/6/1991
54941	1/30/1989
54941	1/30/2001
54941	9/24/2010
54941	6/13/1989
54941	5/11/2020
54964	3/9/2017
54964	3/18/2019
54964	12/20/2020
55105	3/10/2005
55105	8/31/2018
55446	7/13/1996
55511	2/11/2004
55705	8/6/1998
55858	2/18/1992
55997	12/23/1983
56030	1/18/2003
56030	5/14/2009
56030	8/20/1984
56341	11/7/2004
56341	12/5/2016
56341	7/13/2014
56341	5/9/2000
56341	3/14/1988
56341	2/3/2012
56385	5/9/1988
56423	5/7/1998
56423	10/22/2001
56423	12/20/2011
56529	8/26/1994
56529	7/19/2001
56613	11/4/2008
56693	1/5/2013
56715	10/22/1994
56898	3/3/2023
56898	9/20/1991
56898	7/12/2019
56923	3/4/1996
56934	8/30/1987
56934	4/6/2003
56966	1/12/2011
57020	10/28/2020
57020	11/24/1982
57020	6/29/2003
57020	3/7/1989
57083	2/25/2012
57083	10/15/2020
57083	4/3/1985
57083	1/28/1992
57083	7/25/1998
57202	8/23/1996
57202	6/10/1982
57202	6/16/1997
57202	10/13/1984
57202	10/16/1997
57202	1/21/2015
57202	6/29/1985
57243	4/6/2012
57243	6/12/2006
57243	5/9/1986
57326	5/4/2001
57326	11/17/1991
57364	1/13/2007
57403	1/12/2006
57438	11/5/2009
57585	3/10/2021
57859	3/18/2001
58029	4/26/1986
58029	8/20/2020
58154	1/12/1999
58154	8/16/1998
58154	2/17/1983
58154	3/28/2002
58154	11/27/2003
58219	12/3/2001
58219	7/21/1996
58570	5/3/2020
58572	2/18/1989
58572	3/26/2003
58572	11/26/1990
58572	11/16/2016
58572	12/22/2016
58572	4/9/2013
58572	2/3/1986
58753	9/16/2002
58753	4/30/2015
58770	1/16/2023
58770	3/17/1982
58770	9/28/2017
58770	7/3/1986
58770	5/17/1984
58770	8/19/2019
58916	10/29/2021
58974	6/7/2004
58974	5/26/2010
59171	6/30/2009
59567	4/8/1987
59742	7/30/2019
59742	9/27/1991
59742	3/29/2012
59742	6/25/2020
59742	5/22/1986
59784	10/18/2003
60198	9/23/2018
60223	12/11/2014
60223	8/1/2007
60223	3/6/1996
60261	9/12/2000
60261	4/18/2018
60261	6/25/1992
60261	3/6/2006
60360	6/2/1997
60360	10/7/1999
60734	5/21/2010
61317	3/22/2022
61397	8/21/1995
61397	12/4/2003
61521	8/5/1987
61521	8/6/2006
61521	9/21/2003
61717	5/24/2012
61717	3/30/1988
61717	9/3/2021
61741	5/3/2010
61866	11/17/2013
61893	4/12/1982
61893	6/28/1991
61893	7/24/1985
62128	8/18/1983
62133	5/21/2012
62133	3/16/2013
62133	12/5/1991
62133	2/3/2013
62133	8/15/1991
62133	3/13/1987
62439	7/25/1993
62732	5/19/1989
62732	3/14/2016
62927	7/24/2014
62927	6/26/2019
63080	7/8/2004
63167	1/19/1992
63190	2/16/1994
63373	10/3/2012
63373	9/19/2002
63373	12/27/1992
63378	4/23/2018
63486	8/22/2022
63486	8/9/2005
63612	10/10/2003
63700	8/2/2017
63832	11/3/2015
63832	6/18/1992
63832	8/6/2000
63832	6/7/2017
64130	4/6/1985
64130	9/1/2019
64225	3/31/2010
64225	8/3/1982
64290	5/5/1992
64290	6/19/1996
64403	1/8/2020
64505	12/31/2017
64505	9/10/2015
64505	6/13/1984
64513	10/20/2016
64513	6/6/1990
64573	6/15/2016
64690	9/15/2003
64690	10/23/2001
64690	1/23/1993
64690	2/6/1999
64690	6/8/2013
64904	9/22/2009
64925	4/2/1985
64925	8/29/2003
65016	4/24/2011
65141	4/22/2010
65307	11/2/2016
65307	7/7/2016
65385	11/9/1987
65522	1/16/2008
65585	11/3/2013
65585	12/12/1997
65586	10/24/1992
65586	12/15/2006
65673	8/12/1993
65673	8/14/2017
65759	11/3/1999
65767	8/31/2013
66122	4/24/1983
66122	9/1/2020
66122	1/9/1998
66136	7/12/2001
66136	6/5/1995
66136	10/22/2021
66268	1/13/1983
66410	6/24/2012
66508	4/14/2009
66508	1/25/1983
66508	5/17/2009
66673	6/26/2022
66856	4/23/2022
66856	4/19/2011
66856	2/3/2021
66856	7/5/2021
66861	10/2/1992
66926	7/13/2003
67084	2/7/2004
67159	9/4/2014
67242	5/22/2004
67242	7/6/1988
67242	2/15/2008
67291	12/31/1986
67291	4/27/1995
67374	11/25/2001
67374	7/4/2000
67374	3/14/1986
67374	6/9/2005
67374	11/22/2011
67400	9/28/2012
67410	5/4/1989
67410	3/3/2008
67410	7/1/2008
67410	8/31/2005
67410	11/17/2021
67410	1/9/1998
67410	6/11/2019
67478	8/27/2011
67478	10/25/1982
67478	12/22/2014
67478	8/12/2014
67512	10/13/2007
67512	1/22/2011
67760	10/12/2017
67760	4/26/1995
68035	5/13/1987
68138	9/12/1985
68169	5/4/1986
68169	7/29/1997
68275	7/19/2022
68275	11/30/2015
68381	11/6/1997
68381	5/17/1998
68403	3/15/1992
68403	12/8/1984
68403	10/24/2017
68441	9/19/2002
68441	1/24/2021
68441	10/28/1992
68525	11/16/2002
68560	5/29/2008
68988	2/2/1995
68988	1/2/1998
69183	3/18/1983
69183	10/21/2013
69183	1/19/2000
69183	10/29/2002
69183	4/22/2005
69207	9/4/1991
69278	11/30/2009
69278	5/26/2015
69313	5/22/2017
69313	10/19/2003
69474	10/30/1990
69505	4/26/2005
69505	9/14/1995
69505	12/3/2001
69505	7/30/2009
69553	4/28/1990
69553	6/23/2009
69553	4/15/1995
69709	9/18/2003
69709	5/22/2000
69709	8/5/1989
69709	3/23/2017
69709	10/7/1993
69709	1/9/2011
69961	11/8/1986
69961	8/8/2020
69961	8/17/2000
69961	5/19/1989
70009	8/27/2009
70009	12/5/1988
70157	11/9/1996
70157	12/7/1990
70273	10/19/2008
70317	11/1/2010
70342	10/17/2003
70458	7/20/2012
70527	10/4/2007
70527	8/19/1992
70583	3/6/2022
70916	11/28/2007
71011	9/2/2013
71011	4/5/2012
71023	7/8/2003
71529	11/1/2001
71661	3/8/2010
71661	6/15/1989
71782	5/2/2013
71813	4/10/1986
71869	2/12/2020
71869	12/22/2003
71869	12/2/2010
71869	3/19/2015
71907	12/12/2022
71907	3/24/1994
72635	10/15/2005
72635	3/25/2009
72698	9/1/2014
72735	2/7/2011
72735	4/22/2009
73035	6/19/2008
73035	7/6/1999
73038	10/24/2020
73073	5/6/1995
73073	6/16/1992
73073	9/25/2005
73161	9/2/1993
73427	5/23/2010
73427	2/5/2001
73499	8/8/1985
73499	8/6/2008
73499	5/20/1989
73499	5/8/1984
73499	3/12/2002
73533	9/27/2020
73533	8/14/2014
73533	8/4/2017
73533	8/13/1983
74163	1/8/2018
74585	11/7/1989
74585	10/7/2006
74705	9/23/1995
74705	3/7/2014
74802	3/2/2017
74802	2/19/2007
74825	7/10/2021
75135	6/23/2020
75314	4/18/2010
75915	12/27/2012
75923	7/26/2013
75923	4/10/2002
75923	6/26/1990
75978	2/15/2001
76029	10/17/1989
76045	2/18/2019
76045	6/30/2005
76045	1/12/2009
76045	7/10/1997
76090	6/7/2007
76354	8/10/1982
76488	10/8/1989
76555	6/29/2009
76555	12/16/1988
76555	3/14/2011
76736	10/11/2014
76736	5/9/1983
76736	5/17/2021
76736	12/28/2010
76847	8/31/1984
76847	5/2/2019
76847	8/22/1996
76915	9/7/2002
77017	11/29/1989
77082	9/2/2008
77082	2/5/2008
77082	12/13/1993
77082	2/7/1995
77082	12/12/1999
77612	9/4/2007
77726	4/21/2011
77726	9/25/2018
77726	11/18/1982
77739	10/24/1984
77810	9/29/2012
77954	10/6/1993
77954	10/28/1990
78098	10/31/2021
78098	11/10/2006
78108	5/28/1992
78387	10/27/2001
78387	12/18/2007
78387	2/1/1984
78522	12/20/1994
78522	12/29/1993
78573	11/11/2017
78573	2/8/1990
78631	8/25/2015
78631	1/22/2008
78665	9/22/2022
78665	6/26/1995
78665	4/30/1995
78714	1/26/2021
78714	2/29/2020
78714	12/30/1989
78941	10/30/1984
79336	1/9/1998
79336	6/30/2007
79336	3/16/2009
79482	7/23/1998
79482	4/15/2009
79482	2/23/2023
79571	5/8/2014
79571	10/29/1988
79597	7/21/1988
79597	6/22/1993
79614	11/21/1994
79614	5/14/2015
79614	6/24/1982
79614	6/7/1982
79614	12/15/2012
79712	11/19/1986
79712	12/4/1993
79810	7/29/1987
79859	11/10/1985
79859	4/14/1997
79859	12/7/1986
79892	6/15/2012
79892	4/2/1998
79892	8/28/2004
79921	9/25/2020
79921	2/3/1989
79921	6/4/2020
79921	10/3/1985
80254	3/5/2023
80254	8/17/1998
80254	10/25/1994
80254	12/14/1984
80265	10/4/2002
80265	4/6/2005
80265	2/18/2016
80265	11/14/1988
80309	10/1/1994
80309	7/13/2011
80309	2/20/2002
80633	3/6/2023
80633	4/1/1988
80941	5/8/1998
80941	6/15/2019
81057	7/7/1993
81057	3/24/1997
81244	9/17/1989
81356	7/31/2015
81356	5/13/2005
81356	10/5/2010
81380	4/21/2012
81801	11/27/1984
81801	12/8/2005
81801	9/30/1995
81801	7/17/2004
81801	4/5/2004
82044	5/7/2009
82044	2/3/2006
82107	5/25/2002
82107	1/24/1995
82294	6/12/1994
82560	7/16/1997
82560	6/14/1987
82586	5/15/1998
82586	5/5/2019
82586	10/15/1991
82586	5/4/1999
82646	7/26/1997
82772	9/23/2015
82772	4/1/2005
82772	1/4/2013
82772	5/23/1982
82791	4/5/2022
82791	10/27/2011
82791	1/30/2004
82826	9/12/2006
82826	4/30/1982
82955	8/16/1984
82955	3/15/2019
82964	6/1/2003
83056	4/27/1984
83142	6/23/1987
83286	1/26/2008
83286	1/5/2012
83286	10/7/1984
83407	3/11/1984
83651	3/12/1999
83780	9/7/2007
83848	10/3/2011
83848	7/22/2018
83867	5/20/2002
83867	11/3/2002
83867	4/11/2019
83867	6/1/2016
83867	9/10/2012
83867	3/1/1998
83895	9/29/2016
84083	1/16/1989
84083	3/25/2017
84139	7/18/1997
84223	6/11/1989
84307	11/18/2008
84359	8/19/2018
84443	8/25/2001
84566	1/26/2018
84628	4/11/1993
84628	8/31/2014
84628	4/11/1990
84729	2/17/1998
84729	11/19/2010
84729	5/16/2016
84866	9/19/2019
84866	4/29/1997
85104	12/28/2011
85104	12/24/1990
85104	3/26/2020
85104	8/30/2007
85104	4/18/2006
85104	9/21/1987
85104	2/15/2012
85111	5/14/1986
85111	12/18/1994
85111	8/10/2004
85179	11/15/1999
85179	12/15/1995
85179	4/27/2012
85179	9/19/1998
85179	4/24/1989
85338	10/21/2015
85338	10/25/2020
85352	12/10/1991
85375	8/28/2008
85445	4/22/2005
85595	5/26/1997
85595	5/5/2017
85851	1/26/2012
86105	1/26/1990
86235	7/1/1995
86332	8/22/2001
86372	12/27/1991
86543	3/14/2009
86674	7/11/2006
86751	1/31/1998
86760	4/30/2015
86760	6/1/1988
86856	10/24/1999
86873	9/20/1985
87130	5/26/1983
87130	2/26/1984
87130	3/8/1982
87130	8/17/1983
87206	6/23/2008
87287	7/23/2016
87287	3/31/2010
87287	3/23/2020
87440	1/30/2002
87440	2/13/1983
87440	9/10/2013
87583	7/20/2012
87630	9/22/1985
87750	12/11/2016
87843	2/16/2009
87843	12/10/2011
87843	3/12/1989
87843	6/8/2022
88311	8/7/2022
88311	11/8/2012
88437	10/20/2015
88437	7/30/2019
88815	4/4/1991
88815	6/19/2011
88815	10/5/2021
88815	8/23/2006
88815	2/21/2015
88818	1/12/1995
88818	1/11/2005
89166	7/22/1995
89286	5/6/2017
89666	11/26/2020
89666	8/19/1995
89685	9/11/1986
89712	2/26/2021
89712	8/11/2000
89712	11/19/1999
89712	6/27/2016
89712	1/19/1997
89731	10/21/2005
89777	5/9/2016
89899	4/8/1986
90368	1/16/2004
90505	2/7/1989
90505	2/9/2005
90552	4/11/2015
90552	2/7/1995
90552	8/8/1992
90692	5/19/1984
90714	3/16/2006
90783	5/4/1986
90783	3/5/1996
90783	10/19/2012
90783	6/10/2005
91038	5/12/2000
91129	7/24/1985
91180	3/8/1982
91560	7/27/2000
91560	12/24/2015
91560	12/31/1988
91669	1/20/2023
91834	4/4/2018
91873	7/18/2018
91873	11/25/2010
91894	5/24/1995
91894	12/10/1997
92294	6/28/1985
92294	8/30/2008
92607	9/5/2009
92665	3/2/1995
92762	4/22/1983
92844	12/17/2013
92897	11/24/2000
93132	4/21/1987
93132	10/31/2015
93132	10/27/2013
93367	1/8/2022
93367	4/30/1986
93367	12/28/1999
93522	10/2/1997
93522	6/11/2016
93632	2/1/2020
93632	11/24/2004
93741	4/1/1993
93741	4/16/2004
93741	9/6/2008
93867	5/25/1988
93867	2/21/1998
94355	10/18/1993
94355	8/9/1989
94355	5/22/2011
94355	3/24/1987
94355	3/11/1998
94355	12/8/1983
94542	10/25/2022
94883	12/14/1994
94974	9/16/2022
94974	7/3/2011
94974	2/23/2002
95199	5/18/2008
95217	1/30/1999
95304	12/22/2003
95304	4/11/1995
95304	4/5/2009
95304	4/22/1993
95436	9/11/2012
95436	12/10/2017
95436	3/15/2002
95436	6/9/2021
95436	9/14/2016
95485	4/12/1995
95485	6/28/2022
95485	8/28/2021
95485	12/19/2019
95532	6/28/1996
95532	3/25/1983
95559	11/8/1995
95559	2/25/2010
95561	11/5/2007
95561	8/13/1995
95581	12/30/1987
95590	7/18/2015
95600	1/21/1999
95600	12/25/2009
95600	1/8/2004
95600	1/8/1986
95827	7/24/1998
95827	7/29/1991
95827	9/7/2003
95827	6/12/2018
95827	3/7/1983
96027	2/10/1984
96187	5/19/1995
96187	6/8/1986
96194	12/11/1983
96194	8/12/1995
96194	7/18/2012
96194	9/6/2015
96194	5/1/1992
96248	8/2/1983
96357	4/3/1996
96421	3/19/2021
96487	8/25/1994
96487	8/8/1989
96487	6/28/1984
96765	9/15/1995
96789	10/22/2019
96828	3/4/1999
96828	4/20/2002
96828	10/13/1986
96828	4/22/2012
96828	12/10/2022
96828	8/12/2001
97069	2/27/1991
97069	3/2/1995
97619	1/17/2012
97756	12/11/2005
97756	6/2/2017
97756	2/17/2003
97811	10/10/2010
97811	8/4/1983
97811	5/7/2021
97815	1/2/1994
97815	11/28/2020
97860	2/26/2012
97920	10/9/2006
98014	1/30/1997
98053	4/3/1984
98053	9/14/2009
98053	4/17/1983
98073	6/20/1989
98073	12/15/2019
98073	7/20/2014
98073	7/29/2008
98094	7/7/1996
98491	10/15/2016
98559	7/14/2012
;
1 ACCEPTED SOLUTION

Accepted Solutions
jimbarbour
Meteorite | Level 14

It's only going to include rows in the results set where the dates are greater in the second table than the first.

 

from fake_data a, fake_data b
	where a.pat_id = b.pat_id
		and b.visit_date > a.visit_date
		and intck('day', b.visit_date, a.visit_date) < 366;

It's looking for visits after the first visit but within one year of the first visit.  In other words, it's looking to gather the rows of patient who visited more than once in a rolling year period.

 

By the way, if you'll notice, the join is between two ... well sort of virtual instances of the same table.  This is a real cool feature of SQL that you can join tables to themselves.

 

Jim

View solution in original post

3 REPLIES 3
jimbarbour
Meteorite | Level 14

It's only going to include rows in the results set where the dates are greater in the second table than the first.

 

from fake_data a, fake_data b
	where a.pat_id = b.pat_id
		and b.visit_date > a.visit_date
		and intck('day', b.visit_date, a.visit_date) < 366;

It's looking for visits after the first visit but within one year of the first visit.  In other words, it's looking to gather the rows of patient who visited more than once in a rolling year period.

 

By the way, if you'll notice, the join is between two ... well sort of virtual instances of the same table.  This is a real cool feature of SQL that you can join tables to themselves.

 

Jim

axescot78
Quartz | Level 8
that's what I thought it was doing but I thought you would have to specify to compare the earliest date such as with a min() function. thanks!
SASKiwi
PROC Star

I think you've got your start and end dates mixed up. This might work better:

proc sql;
	create table cares_count as
	select distinct a.pat_id, 1 as flag
	from fake_data a, fake_data b
	where a.pat_id = b.pat_id
    and 0 < intck('day', a.visit_date, b.visit_date) < 366;
quit;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 933 views
  • 0 likes
  • 3 in conversation