<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Identify  lack of continuity in data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Identify-lack-of-continuity-in-data/m-p/913374#M360013</link>
    <description>&lt;P&gt;Here is one solution&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input custID YYYYMM;
cards;
1 202301
1 202302
1 202303
1 202304
1 202305
1 202306
2 202304
2 202305
2 202306
3 202301
3 202302
3 202303
3 202304
4 202301
4 202302
4 202303
4 202305
4 202306 
5 202303
5 202304
5 202305
5 202306
6 202301
6 202302
6 202306
;
Run;


proc sql;
create table t_min_max as
select custID,
        min(YYYYMM) as min_month,
		max(YYYYMM) as max_month,
		count(*) as nr_months_With_Data
from have
group by custID
;
quit;

proc sql;
create table ttt as
select a.*,b.min_month,b.max_month,b.nr_months_With_Data,intck("month",input(cat(b.min_month),yymmn6.),input(cat(b.max_month),yymmn6.))+1 as nr_Months_between_min_max,
case when b.nr_months_With_Data=calculated nr_Months_between_min_max  then 1 else 0 end as Ind
from have as a
left join t_min_max  as b
on a.custID=b.custID
;
quit;
 
proc sql;
create  table want as
select custID,  
			max(case when nr_months_With_Data= nr_Months_between_min_max  then 1 else 0 end) as Ind
from ttt
group by custID
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 29 Jan 2024 11:55:29 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2024-01-29T11:55:29Z</dc:date>
    <item>
      <title>Identify  lack of continuity in data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-lack-of-continuity-in-data/m-p/913367#M360007</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have a data set with multiple rows per customer ID.&lt;/P&gt;
&lt;P&gt;Each row represent existence of customer&amp;nbsp; in specific month (YYYYMM).&lt;/P&gt;
&lt;P&gt;My target- For each customer I want to identify if there is lack of continuity in data.&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;CustomerID=1 have full data from JAN2023 till JUN2023&amp;nbsp; (so calculated indicator field will get value=1)&lt;/P&gt;
&lt;P&gt;CustomerID=2 have full data from APR2023 till JUN2023(so calculated indicator field will get value=1)&lt;/P&gt;
&lt;P&gt;CustomerID=3 have full data from JAN2023 till APR2023(so calculated indicator field will get value=1)&lt;/P&gt;
&lt;P&gt;CustomerID=4 have data hole in Apr2023 (so calculated indicator field will get value=0)&lt;/P&gt;
&lt;P&gt;CustomerID=5 have full data from MAR2023 till JUN2023(so calculated indicator field will get value=1)&lt;/P&gt;
&lt;P&gt;CustomerID=6 have data hole in MAR2023,APR2023,MAY2023 (so calculated indicator field will get value=0)&lt;/P&gt;
&lt;P&gt;What is the way to calculate it?&lt;/P&gt;
&lt;P&gt;Remember that desired wanted data set will have one row per customer&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input custID YYYYMM;
cards;
1 202301
1 202302
1 202303
1 202304
1 202305
1 202306
2 202304
2 202305
2 202306
3 202301
3 202302
3 202303
3 202304
4 202301
4 202302
4 202303
4 202305
4 202306 
5 202303
5 202304
5 202305
5 202306
6 202301
6 202302
6 202306
;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2024 11:23:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-lack-of-continuity-in-data/m-p/913367#M360007</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-01-29T11:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: Identify  lack of continuity in data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-lack-of-continuity-in-data/m-p/913369#M360009</link>
      <description>&lt;P&gt;None of those observations have any date. Start by creating an actual date value.&lt;/P&gt;
&lt;P&gt;Use INTCK on the LAGGED date variables with a month to see if the value is one month to set a retained flag for good/bad (1/0).&lt;/P&gt;
&lt;P&gt;Us BY group processing and apparently First and LAST to output.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2024 11:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-lack-of-continuity-in-data/m-p/913369#M360009</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-01-29T11:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: Identify  lack of continuity in data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-lack-of-continuity-in-data/m-p/913374#M360013</link>
      <description>&lt;P&gt;Here is one solution&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input custID YYYYMM;
cards;
1 202301
1 202302
1 202303
1 202304
1 202305
1 202306
2 202304
2 202305
2 202306
3 202301
3 202302
3 202303
3 202304
4 202301
4 202302
4 202303
4 202305
4 202306 
5 202303
5 202304
5 202305
5 202306
6 202301
6 202302
6 202306
;
Run;


proc sql;
create table t_min_max as
select custID,
        min(YYYYMM) as min_month,
		max(YYYYMM) as max_month,
		count(*) as nr_months_With_Data
from have
group by custID
;
quit;

proc sql;
create table ttt as
select a.*,b.min_month,b.max_month,b.nr_months_With_Data,intck("month",input(cat(b.min_month),yymmn6.),input(cat(b.max_month),yymmn6.))+1 as nr_Months_between_min_max,
case when b.nr_months_With_Data=calculated nr_Months_between_min_max  then 1 else 0 end as Ind
from have as a
left join t_min_max  as b
on a.custID=b.custID
;
quit;
 
proc sql;
create  table want as
select custID,  
			max(case when nr_months_With_Data= nr_Months_between_min_max  then 1 else 0 end) as Ind
from ttt
group by custID
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Jan 2024 11:55:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-lack-of-continuity-in-data/m-p/913374#M360013</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-01-29T11:55:29Z</dc:date>
    </item>
    <item>
      <title>Re: Identify  lack of continuity in data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-lack-of-continuity-in-data/m-p/913377#M360015</link>
      <description>&lt;P&gt;&lt;STRONG&gt;BEFORE&lt;/STRONG&gt; you do&amp;nbsp;&lt;STRONG&gt;anything&lt;/STRONG&gt;, convert those useless numbers to SAS date values. After that, it's a simple application of INTCK, e.g.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
indicator = 1;
do until (last.custid);
  set have;
  by custid;
  if intck('month',lag(yyyymm),yyyymm) &amp;gt; 1 and not first.custid then indicator = 0;
end;
keep custid indicator;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, posted from my tablet.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2024 12:18:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-lack-of-continuity-in-data/m-p/913377#M360015</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-01-29T12:18:48Z</dc:date>
    </item>
    <item>
      <title>Re: Identify  lack of continuity in data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-lack-of-continuity-in-data/m-p/913379#M360017</link>
      <description>&lt;P&gt;Here is summary of the solutions:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input custID YYYYMM;
cards;
1 202301
1 202302
1 202303
1 202304
1 202305
1 202306
2 202304
2 202305
2 202306
3 202301
3 202302
3 202303
3 202304
4 202301
4 202302
4 202303
4 202305
4 202306 
5 202303
5 202304
5 202305
5 202306
6 202301
6 202302
6 202306
;
Run;


/****Way1*******************/
/****Way1*******************/
/****Way1*******************/
/****Way1*******************/
Data have_b(Drop=YYYYMM rename=(_yyyymm_ =YYYYMM));
set have;
_yyyymm_=input(cat(YYYYMM),yymmn6.);
format _yyyymm_ date9.;
Run;

data want;
indicator = 1;
do until (last.custid);
set have_b;
by custid;
if intck('month',lag(yyyymm),yyyymm) &amp;gt; 1 and not first.custid then indicator = 0;
end;
keep custid indicator;
run;

/****Way2*******************/
/****Way2*******************/
/****Way2*******************/
proc sql;
create table t_min_max as
select custID,
        min(YYYYMM) as min_month,
		max(YYYYMM) as max_month,
		count(*) as nr_months_With_Data
from have
group by custID
;
quit;

proc sql;
create table ttt as
select a.*,b.min_month,b.max_month,b.nr_months_With_Data,intck("month",input(cat(b.min_month),yymmn6.),input(cat(b.max_month),yymmn6.))+1 as nr_Months_between_min_max,
case when b.nr_months_With_Data=calculated nr_Months_between_min_max  then 1 else 0 end as Ind
from have as a
left join t_min_max  as b
on a.custID=b.custID
;
quit;
 
proc sql;
create  table want as
select custID,  
			max(case when nr_months_With_Data= nr_Months_between_min_max  then 1 else 0 end) as Ind
from ttt
group by custID
;
quit;

 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Jan 2024 12:27:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-lack-of-continuity-in-data/m-p/913379#M360017</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-01-29T12:27:37Z</dc:date>
    </item>
  </channel>
</rss>

