<?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: how to assign sequence number in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-assign-sequence-number/m-p/723808#M224675</link>
    <description>&lt;P&gt;Next code is rested:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   infile datalines dlm='~' dsd truncover;
   input id class $ section $ mark $ stagen seq test $;
datalines;
101~class1~sectiona~~4~1~
101~class1~sectiona~fi~3~2~fi
101~class1~sectiona~~9~3~fi
101~class1~sectiona~~9~4~fi
101~class1~sectiona~~9~5~fi
101~class1~sectiona~last~6~6~last
101~class1~sectiona~~2~7~last
101~class1~sectiona~~3~8~last
101~class1~sectiona~fi~9~9~fi
101~class1~sectiona~~2~10~fi
101~class1~sectiona~~3~11~fi
101~class1~sectiona~~9~12~fi
101~class1~sectiona~last~2~13~last
101~class1~sectiona~~9~14~last
; run;

data want;
 set have;
  by ID class;
     retain test_repeating flag;
     if first.class then do;
	    test_repeating=.;
		flag=.;
	 end;
	 if test='fi' then do;
	    if flag=. then do; test_repeating = 1;  flag=1; end;
	    else test_repeating+1; 
	 end; else
	 if test='last' then do;
	    test_repeating=.; 
	    if flag = 1 then do; 
		    test_repeating=1; 
		    flag=.; 
		end;
	 end;
	 drop flag;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 05 Mar 2021 08:43:45 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2021-03-05T08:43:45Z</dc:date>
    <item>
      <title>how to assign sequence number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-assign-sequence-number/m-p/723788#M224665</link>
      <description>&lt;P&gt;id~class~section~mark~stagen~seq~test&lt;BR /&gt;101~class1~sectiona~~4~1~&lt;BR /&gt;101~class1~sectiona~fi~3~2~fi&lt;BR /&gt;101~class1~sectiona~~9~3~fi&lt;BR /&gt;101~class1~sectiona~~9~4~fi&lt;BR /&gt;101~class1~sectiona~~9~5~fi&lt;BR /&gt;101~class1~sectiona~last~6~6~last&lt;BR /&gt;101~class1~sectiona~~2~7~last&lt;BR /&gt;101~class1~sectiona~~3~8~last&lt;BR /&gt;101~class1~sectiona~fi~9~9~fi&lt;BR /&gt;101~class1~sectiona~~2~10~fi&lt;BR /&gt;101~class1~sectiona~~3~11~fi&lt;BR /&gt;101~class1~sectiona~~9~12~fi&lt;BR /&gt;101~class1~sectiona~last~2~13~last&lt;BR /&gt;101~class1~sectiona~~9~14~last&lt;BR /&gt;Note: delimiter is '~'&lt;/P&gt;
&lt;P&gt;Hi I have one dataset like above and I have to create sequence number test wise&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By variables are id class section seq.&lt;/P&gt;
&lt;P&gt;How to create one variable (repeating) output should be below&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for your ref:&lt;/P&gt;
&lt;P&gt;id~class~section~mark~stagen~seq~test_repeating&lt;/P&gt;
&lt;P&gt;101~class1~sectiona~~4~1~&lt;BR /&gt;101~class1~sectiona~fi~3~2~fi~1&lt;BR /&gt;101~class1~sectiona~~9~3~fi~2&lt;BR /&gt;101~class1~sectiona~~9~4~fi~3&lt;BR /&gt;101~class1~sectiona~~9~5~fi~4&lt;BR /&gt;101~class1~sectiona~last~6~6~last~1&lt;BR /&gt;101~class1~sectiona~~2~7~last~&lt;BR /&gt;101~class1~sectiona~~3~8~last~&lt;BR /&gt;101~class1~sectiona~fi~9~9~fi~1&lt;BR /&gt;101~class1~sectiona~~2~10~fi~2&lt;BR /&gt;101~class1~sectiona~~3~11~fi~3&lt;BR /&gt;101~class1~sectiona~~9~12~fi~4&lt;BR /&gt;101~class1~sectiona~last~2~13~last~1&lt;BR /&gt;101~class1~sectiona~~9~14~last~&lt;/P&gt;
&lt;P&gt;only test='fi' values should go with sequence and test='last' only one number like above dataset&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 07:34:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-assign-sequence-number/m-p/723788#M224665</guid>
      <dc:creator>thanikondharish</dc:creator>
      <dc:date>2021-03-05T07:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: how to assign sequence number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-assign-sequence-number/m-p/723799#M224672</link>
      <description>&lt;P&gt;Is this in a text file?&lt;/P&gt;</description>
      <pubDate>Fri, 05 Mar 2021 08:24:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-assign-sequence-number/m-p/723799#M224672</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-03-05T08:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to assign sequence number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-assign-sequence-number/m-p/723801#M224673</link>
      <description>You can assume both TXT file or normally entered data</description>
      <pubDate>Fri, 05 Mar 2021 08:25:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-assign-sequence-number/m-p/723801#M224673</guid>
      <dc:creator>thanikondharish</dc:creator>
      <dc:date>2021-03-05T08:25:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to assign sequence number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-assign-sequence-number/m-p/723808#M224675</link>
      <description>&lt;P&gt;Next code is rested:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   infile datalines dlm='~' dsd truncover;
   input id class $ section $ mark $ stagen seq test $;
datalines;
101~class1~sectiona~~4~1~
101~class1~sectiona~fi~3~2~fi
101~class1~sectiona~~9~3~fi
101~class1~sectiona~~9~4~fi
101~class1~sectiona~~9~5~fi
101~class1~sectiona~last~6~6~last
101~class1~sectiona~~2~7~last
101~class1~sectiona~~3~8~last
101~class1~sectiona~fi~9~9~fi
101~class1~sectiona~~2~10~fi
101~class1~sectiona~~3~11~fi
101~class1~sectiona~~9~12~fi
101~class1~sectiona~last~2~13~last
101~class1~sectiona~~9~14~last
; run;

data want;
 set have;
  by ID class;
     retain test_repeating flag;
     if first.class then do;
	    test_repeating=.;
		flag=.;
	 end;
	 if test='fi' then do;
	    if flag=. then do; test_repeating = 1;  flag=1; end;
	    else test_repeating+1; 
	 end; else
	 if test='last' then do;
	    test_repeating=.; 
	    if flag = 1 then do; 
		    test_repeating=1; 
		    flag=.; 
		end;
	 end;
	 drop flag;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Mar 2021 08:43:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-assign-sequence-number/m-p/723808#M224675</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-03-05T08:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to assign sequence number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-assign-sequence-number/m-p/724645#M224985</link>
      <description>&lt;P&gt;This modifies the text file in place.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;  %* create text file;
  file "&amp;amp;wdir\test.txt";
  put '101~class1~sectiona~~4~1~';
  put '101~class1~sectiona~fi~3~2~fi';
  put '101~class1~sectiona~~9~3~fi';
  put '101~class1~sectiona~~9~4~fi';
  put '101~class1~sectiona~~9~5~fi';
  put '101~class1~sectiona~last~6~6~last';
  put '101~class1~sectiona~~2~7~last';
  put '101~class1~sectiona~~3~8~last';
  put '101~class1~sectiona~fi~9~9~fi';
  put '101~class1~sectiona~~2~10~fi';
  put '101~class1~sectiona~~3~11~fi';
  put '101~class1~sectiona~~9~12~fi';
  put '101~class1~sectiona~last~2~13~last';
  put '101~class1~sectiona~~9~14~last';
run;

data _null_;   %* alter text file;
  infile  "&amp;amp;wdir\test.txt" sharebuffers;
  input ;
  file  "&amp;amp;wdir\test.txt"; 
  if index(_INFILE_,'~fi') then do;
    N+1;
    LINE= cats(_INFILE_,'~',N); 
    put LINE; 
  end;
  if N &amp;amp; index(_INFILE_,'~last') then do;
    N=0;
    LINE= catt(_INFILE_,'~1');  
    put LINE;
  end;
run;

data _null_;  %* print text file;
  infile "&amp;amp;wdir\test.txt";
  input;
  put _infile_;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Mar 2021 20:44:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-assign-sequence-number/m-p/724645#M224985</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-03-08T20:44:55Z</dc:date>
    </item>
  </channel>
</rss>

