<?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 do concatenate of Observation with do loop so that following output could be generated in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-concatenate-of-Observation-with-do-loop-so-that/m-p/632258#M187434</link>
    <description>&lt;P&gt;Also a good place to use SUBSTR() on the left side of the assignment statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do index=1 to 26 ;
    length char $1 string $26 ;
     char=byte(rank('a')+index-1);
     substr(string,index,1)= char;
     output;
  end;
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    index    char    string

  1       1      a      a
  2       2      b      ab
  3       3      c      abc
  4       4      d      abcd
  5       5      e      abcde
  6       6      f      abcdef
  7       7      g      abcdefg
  8       8      h      abcdefgh
  9       9      i      abcdefghi
 10      10      j      abcdefghij
 11      11      k      abcdefghijk
 12      12      l      abcdefghijkl
 13      13      m      abcdefghijklm
 14      14      n      abcdefghijklmn
 15      15      o      abcdefghijklmno
 16      16      p      abcdefghijklmnop
 17      17      q      abcdefghijklmnopq
 18      18      r      abcdefghijklmnopqr
 19      19      s      abcdefghijklmnopqrs
 20      20      t      abcdefghijklmnopqrst
 21      21      u      abcdefghijklmnopqrstu
 22      22      v      abcdefghijklmnopqrstuv
 23      23      w      abcdefghijklmnopqrstuvw
 24      24      x      abcdefghijklmnopqrstuvwx
 25      25      y      abcdefghijklmnopqrstuvwxy
 26      26      z      abcdefghijklmnopqrstuvwxyz
&lt;/PRE&gt;</description>
    <pubDate>Sun, 15 Mar 2020 16:42:18 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-03-15T16:42:18Z</dc:date>
    <item>
      <title>How to do concatenate of Observation with do loop so that following output could be generated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-concatenate-of-Observation-with-do-loop-so-that/m-p/632223#M187419</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 516px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/36890iAE37C81644E8D6A2/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Have;
Set Some;
	Do i=1 to 26 until (i=ORD);
		Out=Compbl(Substr(ALPHA,1,1)||''||Substr(ALPHA,1,1));
		Output;
	end;
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 15 Mar 2020 06:38:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-concatenate-of-Observation-with-do-loop-so-that/m-p/632223#M187419</guid>
      <dc:creator>Rakesh93</dc:creator>
      <dc:date>2020-03-15T06:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to do concatenate of Observation with do loop so that following output could be generated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-concatenate-of-Observation-with-do-loop-so-that/m-p/632224#M187420</link>
      <description>&lt;P&gt;I Have tried with above code but i couldn't get the output.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Mar 2020 06:42:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-concatenate-of-Observation-with-do-loop-so-that/m-p/632224#M187420</guid>
      <dc:creator>Rakesh93</dc:creator>
      <dc:date>2020-03-15T06:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to do concatenate of Observation with do loop so that following output could be generated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-concatenate-of-Observation-with-do-loop-so-that/m-p/632225#M187421</link>
      <description>&lt;P&gt;It's a simple do loop, with the&amp;nbsp;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=n1jfxetjdn0nxan1w4e64c7rouz9.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;BYTE&lt;/A&gt;&amp;nbsp;function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
length string $26;
do i = 1 to 26;
  char = byte(i + offset);
  string = cats(string,char);
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You need to replace "offset" with the correct value to start in the right position of the ASCII table.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Mar 2020 06:49:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-concatenate-of-Observation-with-do-loop-so-that/m-p/632225#M187421</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-15T06:49:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to do concatenate of Observation with do loop so that following output could be generated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-concatenate-of-Observation-with-do-loop-so-that/m-p/632230#M187423</link>
      <description>Can you describe how byte function and this whole code works??&lt;BR /&gt;</description>
      <pubDate>Sun, 15 Mar 2020 07:43:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-concatenate-of-Observation-with-do-loop-so-that/m-p/632230#M187423</guid>
      <dc:creator>Rakesh93</dc:creator>
      <dc:date>2020-03-15T07:43:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to do concatenate of Observation with do loop so that following output could be generated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-concatenate-of-Observation-with-do-loop-so-that/m-p/632231#M187424</link>
      <description>&lt;P&gt;I explicitly linked to the documentation for you to read. In the same place (navigation pane to the left) you can also find the cats() function. do loop and output are self-explaining.&lt;/P&gt;</description>
      <pubDate>Sun, 15 Mar 2020 08:14:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-concatenate-of-Observation-with-do-loop-so-that/m-p/632231#M187424</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-15T08:14:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to do concatenate of Observation with do loop so that following output could be generated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-concatenate-of-Observation-with-do-loop-so-that/m-p/632232#M187425</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/294186"&gt;@Rakesh93&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Can you describe how byte function and this whole code works??&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The best way to answer your question is to search the specific functions&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is &lt;U&gt;searching&lt;/U&gt; google "&lt;STRONG&gt;sas documentation &amp;lt;function&amp;gt;&lt;/STRONG&gt;".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The BYTE function converts the ascci numeric value into a character.&lt;/P&gt;
&lt;P&gt;CATS function combines concatenation with compress.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Mar 2020 08:19:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-concatenate-of-Observation-with-do-loop-so-that/m-p/632232#M187425</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-03-15T08:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to do concatenate of Observation with do loop so that following output could be generated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-concatenate-of-Observation-with-do-loop-so-that/m-p/632242#M187430</link>
      <description>&lt;P&gt;Here as a variation of what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;posted. All the functions used are documented &lt;A href="https://go.documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n01f5qrjoh9h4hn1olbdpb5pr2td.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;The basic idea of the code: Loop over the decimal values from an ASCII (or EBCDIC) table. Start the loop with &lt;STRONG&gt;a&lt;/STRONG&gt; as the first letter and end with &lt;STRONG&gt;z&lt;/STRONG&gt; as the last letter. If you look into an ASCII table an &lt;STRONG&gt;a&lt;/STRONG&gt; has a decimal value of &lt;STRONG&gt;97&lt;/STRONG&gt;, and a &lt;STRONG&gt;z&lt;/STRONG&gt; a value of &lt;STRONG&gt;122&lt;/STRONG&gt;. So if we know where to start and end then we can just implement a simple do loop and then use the SAS &lt;A href="https://go.documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n1jfxetjdn0nxan1w4e64c7rouz9.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;byte()&lt;/A&gt; function to convert the decimal value to it's character representation. Nicely SAS also provides a &lt;A href="https://go.documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p0m5k2s76pmv9pn1n1lu3vfyq8s4.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;rank()&lt;/A&gt; function which does the opposite to the byte() function: It takes a character and returns its decimal value. So using rank() we can easily determine the start and stop value for a do loop - and then use the values of the do loop counter in the byte() functions to get the characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  format dec_val z3.;
  length char $1 string $26;
  _start=rank('a');
  _stop =rank('z');
  do dec_val = _start to _stop;
    char = byte(dec_val);
    string = cats(string,char);
    output;
  end;
  drop _:;
  stop;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Mar 2020 10:33:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-concatenate-of-Observation-with-do-loop-so-that/m-p/632242#M187430</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-03-15T10:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to do concatenate of Observation with do loop so that following output could be generated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-concatenate-of-Observation-with-do-loop-so-that/m-p/632257#M187433</link>
      <description>&lt;P&gt;Rank() function may also help:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
length string $26;
do i = rank("A") to rank("Z");
  char = byte(i);
  string = cats(string,char);
  output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Sun, 15 Mar 2020 15:45:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-concatenate-of-Observation-with-do-loop-so-that/m-p/632257#M187433</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-03-15T15:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to do concatenate of Observation with do loop so that following output could be generated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-concatenate-of-Observation-with-do-loop-so-that/m-p/632258#M187434</link>
      <description>&lt;P&gt;Also a good place to use SUBSTR() on the left side of the assignment statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do index=1 to 26 ;
    length char $1 string $26 ;
     char=byte(rank('a')+index-1);
     substr(string,index,1)= char;
     output;
  end;
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    index    char    string

  1       1      a      a
  2       2      b      ab
  3       3      c      abc
  4       4      d      abcd
  5       5      e      abcde
  6       6      f      abcdef
  7       7      g      abcdefg
  8       8      h      abcdefgh
  9       9      i      abcdefghi
 10      10      j      abcdefghij
 11      11      k      abcdefghijk
 12      12      l      abcdefghijkl
 13      13      m      abcdefghijklm
 14      14      n      abcdefghijklmn
 15      15      o      abcdefghijklmno
 16      16      p      abcdefghijklmnop
 17      17      q      abcdefghijklmnopq
 18      18      r      abcdefghijklmnopqr
 19      19      s      abcdefghijklmnopqrs
 20      20      t      abcdefghijklmnopqrst
 21      21      u      abcdefghijklmnopqrstu
 22      22      v      abcdefghijklmnopqrstuv
 23      23      w      abcdefghijklmnopqrstuvw
 24      24      x      abcdefghijklmnopqrstuvwx
 25      25      y      abcdefghijklmnopqrstuvwxy
 26      26      z      abcdefghijklmnopqrstuvwxyz
&lt;/PRE&gt;</description>
      <pubDate>Sun, 15 Mar 2020 16:42:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-concatenate-of-Observation-with-do-loop-so-that/m-p/632258#M187434</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-15T16:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to do concatenate of Observation with do loop so that following output could be generated</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-concatenate-of-Observation-with-do-loop-so-that/m-p/632259#M187435</link>
      <description>&lt;P&gt;If the real goal is to get the string abcd...z then you don't need a loop or the BYTE() function.&amp;nbsp; Just use the COLLATE() function instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  length string $26;
  string=collate(rank('a'),rank('z'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 15 Mar 2020 16:45:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-concatenate-of-Observation-with-do-loop-so-that/m-p/632259#M187435</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-15T16:45:30Z</dc:date>
    </item>
  </channel>
</rss>

