<?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: Create flag for every 3 records in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-flag-for-every-3-records/m-p/559329#M156169</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/209685"&gt;@thanikondharish&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Sashelp.class has 19 records .Now create one new variable like for every three records 1-3&lt;BR /&gt;Ex:&lt;BR /&gt;1-3&lt;BR /&gt;1-3&lt;BR /&gt;1-3&lt;BR /&gt;4-6&lt;BR /&gt;4-6&lt;BR /&gt;4-6&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;And since the 19th record is the only one in the last "every three records" what should the value look like??????&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 16 May 2019 14:38:07 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-05-16T14:38:07Z</dc:date>
    <item>
      <title>Create flag for every 3 records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-flag-for-every-3-records/m-p/559261#M156146</link>
      <description>Sashelp.class has 19 records .Now create one new variable like for every three records 1-3&lt;BR /&gt;Ex:&lt;BR /&gt;1-3&lt;BR /&gt;1-3&lt;BR /&gt;1-3&lt;BR /&gt;4-6&lt;BR /&gt;4-6&lt;BR /&gt;4-6</description>
      <pubDate>Thu, 16 May 2019 10:25:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-flag-for-every-3-records/m-p/559261#M156146</guid>
      <dc:creator>thanikondharish</dc:creator>
      <dc:date>2019-05-16T10:25:27Z</dc:date>
    </item>
    <item>
      <title>Re: Create flag for every 3 records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-flag-for-every-3-records/m-p/559262#M156147</link>
      <description />
      <pubDate>Thu, 16 May 2019 10:25:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-flag-for-every-3-records/m-p/559262#M156147</guid>
      <dc:creator>thanikondharish</dc:creator>
      <dc:date>2019-05-16T10:25:51Z</dc:date>
    </item>
    <item>
      <title>Re: Create flag for every 3 records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-flag-for-every-3-records/m-p/559263#M156148</link>
      <description>&lt;P&gt;Do you want to create a new &lt;STRONG&gt;variable&amp;nbsp;&lt;/STRONG&gt;for every three records in sashelp.class?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And what does your final result look like?&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2019 10:30:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-flag-for-every-3-records/m-p/559263#M156148</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-05-16T10:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: Create flag for every 3 records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-flag-for-every-3-records/m-p/559266#M156150</link>
      <description>Single data set and sashelp.class has 19 records so new variable should be&lt;BR /&gt;like this&lt;BR /&gt;OBS. Flag&lt;BR /&gt;1. 1-3&lt;BR /&gt;2. 1-3&lt;BR /&gt;...........&lt;BR /&gt;19. 19-21&lt;BR /&gt;</description>
      <pubDate>Thu, 16 May 2019 10:33:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-flag-for-every-3-records/m-p/559266#M156150</guid>
      <dc:creator>thanikondharish</dc:creator>
      <dc:date>2019-05-16T10:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: Create flag for every 3 records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-flag-for-every-3-records/m-p/559267#M156151</link>
      <description>&lt;P&gt;Please show us the code you already tried for your homework.&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2019 10:35:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-flag-for-every-3-records/m-p/559267#M156151</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-05-16T10:35:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create flag for every 3 records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-flag-for-every-3-records/m-p/559274#M156155</link>
      <description>&lt;P&gt;Hope this will help , check the want variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set sashelp.class;
retain new3 new4 want;
if mod(_N_+2,3)=0 then new=1;
else new+1;
if new&amp;gt;1 then new2=.;
else new2=new;
if new2 ne . then new3=_n_;
if new2 ne . then new4=_n_+2;
want=catx('-',put(new3,best.),put(new4,best.));
drop new:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 May 2019 11:16:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-flag-for-every-3-records/m-p/559274#M156155</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-05-16T11:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: Create flag for every 3 records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-flag-for-every-3-records/m-p/559293#M156158</link>
      <description>&lt;P&gt;To give you some hints:&lt;/P&gt;
&lt;P&gt;This can be achieved rather easily.&lt;/P&gt;
&lt;P&gt;You need one retained variable that contains your group string.&lt;/P&gt;
&lt;P&gt;Every time mod(_n_,3) hits 1, you set this variable, and you can calculate the necessary parts of the string from the current _n_.&lt;/P&gt;
&lt;P&gt;The final data step needs only 5 statements (including "data" and "run").&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking forward to seeing your attempt.&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2019 12:58:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-flag-for-every-3-records/m-p/559293#M156158</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-05-16T12:58:46Z</dc:date>
    </item>
    <item>
      <title>Re: Create flag for every 3 records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-flag-for-every-3-records/m-p/559294#M156159</link>
      <description>&lt;P&gt;What is the logic as you required i didn't get&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Anand&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2019 13:01:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-flag-for-every-3-records/m-p/559294#M156159</guid>
      <dc:creator>BrahmanandaRao</dc:creator>
      <dc:date>2019-05-16T13:01:25Z</dc:date>
    </item>
    <item>
      <title>Re: Create flag for every 3 records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-flag-for-every-3-records/m-p/559329#M156169</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/209685"&gt;@thanikondharish&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Sashelp.class has 19 records .Now create one new variable like for every three records 1-3&lt;BR /&gt;Ex:&lt;BR /&gt;1-3&lt;BR /&gt;1-3&lt;BR /&gt;1-3&lt;BR /&gt;4-6&lt;BR /&gt;4-6&lt;BR /&gt;4-6&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;And since the 19th record is the only one in the last "every three records" what should the value look like??????&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2019 14:38:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-flag-for-every-3-records/m-p/559329#M156169</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-16T14:38:07Z</dc:date>
    </item>
    <item>
      <title>Re: Create flag for every 3 records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-flag-for-every-3-records/m-p/559336#M156172</link>
      <description>&lt;P&gt;Looks like a simple arithmetic problem.&amp;nbsp; If you want the last flag value to reflect the actual number of observations then use the NOBS= option on the SET statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set sashelp.class nobs=nobs;
 length flag $10 ;
 flag=catx('-',int((_n_-1)/3)*3+1,min(int((_n_-1)/3)*3+3,nobs));
run;
proc print ;
var name flag;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    Name       flag

  1    Alfred     1-3
  2    Alice      1-3
  3    Barbara    1-3
  4    Carol      4-6
  5    Henry      4-6
  6    James      4-6
  7    Jane       7-9
  8    Janet      7-9
  9    Jeffrey    7-9
 10    John       10-12
 11    Joyce      10-12
 12    Judy       10-12
 13    Louise     13-15
 14    Mary       13-15
 15    Philip     13-15
 16    Robert     16-18
 17    Ronald     16-18
 18    Thomas     16-18
 19    William    19-19&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 May 2019 15:55:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-flag-for-every-3-records/m-p/559336#M156172</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-16T15:55:20Z</dc:date>
    </item>
  </channel>
</rss>

