<?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 Aggregating data on specific status variables for each time the unique id is updated in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-on-specific-status-variables-for-each-time-the/m-p/527874#M143995</link>
    <description>&lt;P&gt;&lt;FONT color="#000000"&gt;Hello all,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;I'm hoping to create an aggregate dataset on specific statuses that&amp;nbsp;produces a rolling count of&amp;nbsp;cases by the UID between each date update across a range of dates.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#000000"&gt;The main criteria is to count each UID from the date it first appears in a specified status until the day before the next date update. Any UID on their only/final update should continue to be counted in the status for each new date that appears until the next&amp;nbsp;date updated. &lt;FONT color="#000000"&gt;&lt;FONT color="#000000"&gt;I've providing detail on&amp;nbsp;how it should&amp;nbsp;work for each UID in individually for status 1:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;-&amp;nbsp;Looking at UID for A it&amp;nbsp;first enters on 01JAN19 and remains in the status until 05JAN19.The output for&amp;nbsp;would count a 1 from 01JAN19 to 04JAN19 until the case moves to&amp;nbsp;a different status.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;- Looking at&amp;nbsp;UID for&amp;nbsp;B it&amp;nbsp;first enters on 02JAN19 and doesn't move out of this status in the sample. The output&amp;nbsp;would continually count a 1 from 02JAN19 for&amp;nbsp;each date&amp;nbsp;until&amp;nbsp;B is updated.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;-&amp;nbsp;Looking at UID for&amp;nbsp;C it first enters on 04JAN19 and remains in the status until 06JAN19.The output for&amp;nbsp;would count a 1 from 04JAN19 to 05JAN19 until the case moves to&amp;nbsp;a different status.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;- This would be a&amp;nbsp;combined count&amp;nbsp;for all UIDs for each status by date for the final output.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;I'm using SAS EG 7.1 and&amp;nbsp;have included below&amp;nbsp;SAS code that generates a sample of&amp;nbsp;how my&amp;nbsp;data is structured and&amp;nbsp;what the desired output would look. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Any other questions or further information required I can provide more detail.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Many thanks in advance,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Sandy&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.have;
	input UID $1. DATE :date9. STATUS 1.;
	format date date9.;
	infile datalines dlm=',';
	datalines;
A,01JAN2019,1
A,05JAN2019,2
A,07JAN2019,3
B,02JAN2019,1
C,04JAN2019,1
C,06JAN2019,2
C,07JAN2019,3
;
run;

data work.want;
	input DATE :date9. STATUS1 :1. STATUS2 :1. STATUS3 :1.;
	format date date9.;
	infile datalines dlm=',';
	datalines;
01JAN2019,1,0,0
02JAN2019,2,0,0
03JAN2019,2,0,0
04JAN2019,3,0,0
05JAN2019,2,1,0
06JAN2019,1,2,0
07JAN2019,1,0,2
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 16 Jan 2019 22:22:05 GMT</pubDate>
    <dc:creator>Sanflo</dc:creator>
    <dc:date>2019-01-16T22:22:05Z</dc:date>
    <item>
      <title>Aggregating data on specific status variables for each time the unique id is updated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-on-specific-status-variables-for-each-time-the/m-p/527874#M143995</link>
      <description>&lt;P&gt;&lt;FONT color="#000000"&gt;Hello all,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;I'm hoping to create an aggregate dataset on specific statuses that&amp;nbsp;produces a rolling count of&amp;nbsp;cases by the UID between each date update across a range of dates.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#000000"&gt;&lt;FONT color="#000000"&gt;The main criteria is to count each UID from the date it first appears in a specified status until the day before the next date update. Any UID on their only/final update should continue to be counted in the status for each new date that appears until the next&amp;nbsp;date updated. &lt;FONT color="#000000"&gt;&lt;FONT color="#000000"&gt;I've providing detail on&amp;nbsp;how it should&amp;nbsp;work for each UID in individually for status 1:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;-&amp;nbsp;Looking at UID for A it&amp;nbsp;first enters on 01JAN19 and remains in the status until 05JAN19.The output for&amp;nbsp;would count a 1 from 01JAN19 to 04JAN19 until the case moves to&amp;nbsp;a different status.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;- Looking at&amp;nbsp;UID for&amp;nbsp;B it&amp;nbsp;first enters on 02JAN19 and doesn't move out of this status in the sample. The output&amp;nbsp;would continually count a 1 from 02JAN19 for&amp;nbsp;each date&amp;nbsp;until&amp;nbsp;B is updated.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;-&amp;nbsp;Looking at UID for&amp;nbsp;C it first enters on 04JAN19 and remains in the status until 06JAN19.The output for&amp;nbsp;would count a 1 from 04JAN19 to 05JAN19 until the case moves to&amp;nbsp;a different status.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;- This would be a&amp;nbsp;combined count&amp;nbsp;for all UIDs for each status by date for the final output.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;I'm using SAS EG 7.1 and&amp;nbsp;have included below&amp;nbsp;SAS code that generates a sample of&amp;nbsp;how my&amp;nbsp;data is structured and&amp;nbsp;what the desired output would look. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Any other questions or further information required I can provide more detail.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Many thanks in advance,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Sandy&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.have;
	input UID $1. DATE :date9. STATUS 1.;
	format date date9.;
	infile datalines dlm=',';
	datalines;
A,01JAN2019,1
A,05JAN2019,2
A,07JAN2019,3
B,02JAN2019,1
C,04JAN2019,1
C,06JAN2019,2
C,07JAN2019,3
;
run;

data work.want;
	input DATE :date9. STATUS1 :1. STATUS2 :1. STATUS3 :1.;
	format date date9.;
	infile datalines dlm=',';
	datalines;
01JAN2019,1,0,0
02JAN2019,2,0,0
03JAN2019,2,0,0
04JAN2019,3,0,0
05JAN2019,2,1,0
06JAN2019,1,2,0
07JAN2019,1,0,2
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Jan 2019 22:22:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-on-specific-status-variables-for-each-time-the/m-p/527874#M143995</guid>
      <dc:creator>Sanflo</dc:creator>
      <dc:date>2019-01-16T22:22:05Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregating data on specific status variables for each time the unique id is updated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-on-specific-status-variables-for-each-time-the/m-p/528209#M144124</link>
      <description>&lt;P&gt;I find the question very unclear but his will get the ball rolling.&lt;/P&gt;
&lt;P&gt;Does this do what you want?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data DATES;
  merge HAVE(rename=(DATE=CURR_DATE))
        HAVE(firstobs=2 keep=UID DATE rename=(UID=NEXT_UID DATE=NEXT_DATE));
  format DATE date9.;
  retain TOGGLE ;
  if UID ne lag(UID) then TOGGLE=0;                      %* New UID, reset in/out flag;
  TOGGLE=^TOGGLE;
  if UID=NEXT_UID then do DATE=CURR_DATE to NEXT_DATE-1; %* Fill missing dates to value in next record;
    output;
  end;
  else do DATE=CURR_DATE to today();                     %* Last record for UID, fill date till today;
    output;
  end;
  drop CURR_DATE NEXT_UID NEXT_DATE STATUS;
run;

proc sql;
  select DATE, sum(TOGGLE) as STATUS 
  from DATES
  group by DATE 
  order by DATE ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r b header" scope="col"&gt;DATE&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;STATUS&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;01JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;02JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;03JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;04JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;05JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;06JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;07JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;08JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;09JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;10JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;11JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;12JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;13JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;14JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;15JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;16JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;17JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;18JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 17 Jan 2019 23:31:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregating-data-on-specific-status-variables-for-each-time-the/m-p/528209#M144124</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-01-17T23:31:24Z</dc:date>
    </item>
  </channel>
</rss>

