<?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: Reminder by Group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reminder-by-Group/m-p/312060#M67614</link>
    <description>&lt;P&gt;Did you change your sample from your first demo of what you want ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;anyhow, I have run next code and it gives output exactly as wanted:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
input loc $ flag;
cards;
AA 1
AA 1
AA 1
AA 1
AA 0
AA 0
AA 0
AA 0
AB 1
AB 1
AB 1
AB 1
AB 1
AB 0
AB 0
AB 0
AB 0
;
run;

data want;
 set temp;
  by loc notsorted flag;
     retain count count1;
     if first.flag then do; count=0; count1=1; end;
     if flag=0 then link flagz; else
     if flag=1 then link flag1; else
     put '** Flag error on line ' _N_  flag=;
     drop count count1;
return;
flag1:
     count+1;
     if mod(count,4)=0 then count1+1;
     status = 'C'||left(count1);
return;
flagz:
     count+1;
     if mod(count,5)=0 then count1+1;
     status = 'D'||left(count1);
return;  
run;
     
     
             
     
     
     
     &lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 16 Nov 2016 18:16:23 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2016-11-16T18:16:23Z</dc:date>
    <item>
      <title>Reminder by Group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reminder-by-Group/m-p/312053#M67611</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have data in the following format (First 2 columns). The third column 'STATUS' is my desired output. I want to generate serial numbers based on variable 'Flag' by a grouping variable 'LOC'. If flag is equal to 1, SAS should create a variable 'Status' which contains same serial number of every three rows. For example, for a group LOC =AA , the first 3 rows have value 'C1' in the table below and the next row has value 'C2'. Had it contain two more values, the next 2&amp;nbsp;rows would have a value 'C2' and so on (i.e. 'C3', 'C4'....), If Flag = 0, it should create serial number of every four rows (instead of 3).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 144pt;" border="0" width="192" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL style="width: 48pt;" span="3" width="64" /&gt; &lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR style="height: 16.5pt;"&gt;
&lt;TD colspan="2" width="128" height="22" class="xl72" style="height: 16.5pt; width: 96pt;"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;INPUT&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="64" class="xl74" style="width: 48pt;"&gt;&amp;nbsp;&lt;STRONG&gt;OUTPUT&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl69" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;LOC&lt;/TD&gt;
&lt;TD width="64" class="xl70" style="border-top: none; border-left: none; width: 48pt;"&gt;FLAG&lt;/TD&gt;
&lt;TD width="64" class="xl71" style="border-top: none; border-left: none; width: 48pt;"&gt;STATUS&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl64" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;AA&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-top: none; border-left: none; width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;C1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl64" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;AA&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-top: none; border-left: none; width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;C1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl64" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;AA&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-top: none; border-left: none; width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;C1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl64" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;AA&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-top: none; border-left: none; width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;C2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl64" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;AA&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-top: none; border-left: none; width: 48pt;"&gt;0&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;D1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl64" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;AA&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-top: none; border-left: none; width: 48pt;"&gt;0&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;D1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl64" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;AA&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-top: none; border-left: none; width: 48pt;"&gt;0&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;D1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl64" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;AA&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-top: none; border-left: none; width: 48pt;"&gt;0&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;D1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl64" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;AB&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-top: none; border-left: none; width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;C1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl64" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;AB&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-top: none; border-left: none; width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;C1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl64" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;AB&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-top: none; border-left: none; width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;C1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl64" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;AB&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-top: none; border-left: none; width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;C2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl64" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;AB&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-top: none; border-left: none; width: 48pt;"&gt;1&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;C2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl64" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;AB&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-top: none; border-left: none; width: 48pt;"&gt;0&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;D1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl64" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;AB&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-top: none; border-left: none; width: 48pt;"&gt;0&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;D1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD width="64" height="20" class="xl64" style="height: 15.0pt; border-top: none; width: 48pt;"&gt;AB&lt;/TD&gt;
&lt;TD width="64" class="xl63" style="border-top: none; border-left: none; width: 48pt;"&gt;0&lt;/TD&gt;
&lt;TD class="xl65" style="border-top: none; border-left: none;"&gt;D1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD width="64" height="21" class="xl66" style="height: 15.75pt; border-top: none; width: 48pt;"&gt;AB&lt;/TD&gt;
&lt;TD width="64" class="xl67" style="border-top: none; border-left: none; width: 48pt;"&gt;0&lt;/TD&gt;
&lt;TD class="xl68" style="border-top: none; border-left: none;"&gt;D1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The below is the sample SAS code for creating this dataset. It's just the small sample of the large data i have in the same format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
input loc $ flag;
cards;
AA 1
AA 1
AA 1
AA 1
AA 0
AA 0
AA 0
AA 0
AA 1
AB 1
AB 1
AB 1
AB 0
AB 0
AB 0
AB 0
;
run;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Nov 2016 17:37:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reminder-by-Group/m-p/312053#M67611</guid>
      <dc:creator>Ujjawal</dc:creator>
      <dc:date>2016-11-16T17:37:12Z</dc:date>
    </item>
    <item>
      <title>Re: Reminder by Group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reminder-by-Group/m-p/312060#M67614</link>
      <description>&lt;P&gt;Did you change your sample from your first demo of what you want ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;anyhow, I have run next code and it gives output exactly as wanted:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
input loc $ flag;
cards;
AA 1
AA 1
AA 1
AA 1
AA 0
AA 0
AA 0
AA 0
AB 1
AB 1
AB 1
AB 1
AB 1
AB 0
AB 0
AB 0
AB 0
;
run;

data want;
 set temp;
  by loc notsorted flag;
     retain count count1;
     if first.flag then do; count=0; count1=1; end;
     if flag=0 then link flagz; else
     if flag=1 then link flag1; else
     put '** Flag error on line ' _N_  flag=;
     drop count count1;
return;
flag1:
     count+1;
     if mod(count,4)=0 then count1+1;
     status = 'C'||left(count1);
return;
flagz:
     count+1;
     if mod(count,5)=0 then count1+1;
     status = 'D'||left(count1);
return;  
run;
     
     
             
     
     
     
     &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Nov 2016 18:16:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reminder-by-Group/m-p/312060#M67614</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-16T18:16:23Z</dc:date>
    </item>
    <item>
      <title>Re: Reminder by Group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reminder-by-Group/m-p/312061#M67615</link>
      <description>&lt;P&gt;Assumes the data is sorted by LOC;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set temp;
   by loc;
   retain rowcount;
   length status $ 4.;
   if first.loc then rowcount=0;
   if flag then do;
      rowcount+1;
      count = ceil(rowcount/3);
      status = cats("C",count);
   end;
   else Status = "D1";
   drop rowcount count;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 Nov 2016 18:17:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reminder-by-Group/m-p/312061#M67615</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-16T18:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: Reminder by Group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reminder-by-Group/m-p/312080#M67620</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw﻿&lt;/a&gt;&amp;nbsp;for your elegant solution. I just minor tweaked it for my requirement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set temp;
   by loc;
   retain rowcount;
   length status $ 4.;
   if first.loc then rowcount=0;
   if flag then do;
      rowcount+1;
      count = ceil(rowcount/3);
      status = cats("C",count);
	   rowcount=0;
   end;
   else do;
   rowcount+1;
   count = ceil(rowcount/4);
   status = cats("D",count);
   end;
   drop rowcount count;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Nov 2016 18:59:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reminder-by-Group/m-p/312080#M67620</guid>
      <dc:creator>Ujjawal</dc:creator>
      <dc:date>2016-11-16T18:59:57Z</dc:date>
    </item>
  </channel>
</rss>

