<?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 a string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-string/m-p/499352#M132864</link>
    <description>&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%to&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; j=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%to&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; upcase(trim(boap&amp;amp;j)) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; boap&amp;amp;j &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;j &amp;lt; &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"*"&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; into :&lt;/FONT&gt;&lt;FONT color="#ff0000" face="Courier New" size="3"&gt;state1&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; seperated by &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"|"&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;from billplan;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;quit&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So number of rows is 4 so first time it loops 4 times and then it loops three times for&amp;nbsp; three variables all three variables are separated by * and each row is separated by |and that's how the variable State1 at the end looks like&lt;/P&gt;
&lt;P&gt;Ins*Status*Cycle|Total*Pays |Cust |Num*Disc*Early&lt;/P&gt;</description>
    <pubDate>Thu, 27 Sep 2018 02:52:08 GMT</pubDate>
    <dc:creator>chennupriya</dc:creator>
    <dc:date>2018-09-27T02:52:08Z</dc:date>
    <item>
      <title>Create a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-string/m-p/499341#M132859</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;
&lt;P&gt;I have a sas dataset billplan which has below three rows in the dataset and i want to loop through &lt;BR /&gt;those 3 rows for boap1 , boap2 and boap3 variables and create a string&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;first three variables of row1 are seperated by * and then | then two variables of row2 are seperated by * and then |&lt;BR /&gt;and one variable of row3 and loop ends&lt;/P&gt;
&lt;P&gt;&amp;nbsp;finally state1 should resolve to&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;Ins*Status*Cycle|Total*Pays|Cust&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Table BillPLan&lt;/P&gt;
&lt;TABLE width="771"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="197"&gt;&lt;STRONG&gt;SName &lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="116"&gt;&lt;STRONG&gt;tst&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="236"&gt;&lt;STRONG&gt;boap1&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="110"&gt;&lt;STRONG&gt;boap2&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="112"&gt;&lt;STRONG&gt;boap3&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;STRONG&gt;Score&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;h&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="236"&gt;&lt;STRONG&gt;Ins&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="110"&gt;&lt;STRONG&gt;Status&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="112"&gt;&lt;STRONG&gt;Cycle&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;STRONG&gt;Sex&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;h&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="236"&gt;&lt;STRONG&gt;Total&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;Pays&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;STRONG&gt;Age&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;h&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="236"&gt;&lt;STRONG&gt;Cust&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;STRONG&gt;Height &lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;h&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="236"&gt;&lt;STRONG&gt;Num&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;Disc&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;STRONG&gt;Early&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone please help ?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 02:44:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-string/m-p/499341#M132859</guid>
      <dc:creator>chennupriya</dc:creator>
      <dc:date>2018-09-27T02:44:56Z</dc:date>
    </item>
    <item>
      <title>Re: Create a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-string/m-p/499344#M132861</link>
      <description>&lt;P&gt;This seems like it should work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set billplan end=done;&lt;/P&gt;
&lt;P&gt;length this_line $ 50 state1 $ 100;&lt;/P&gt;
&lt;P&gt;retain state1;&lt;/P&gt;
&lt;P&gt;this_line = catx('*', boap1, boap2, boap3);&lt;/P&gt;
&lt;P&gt;state1 = catx('|', state1, this_line);&lt;/P&gt;
&lt;P&gt;if done;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Still, unless you tell us more it is difficult to accept the usefulness of this result.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 01:53:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-string/m-p/499344#M132861</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-09-27T01:53:31Z</dc:date>
    </item>
    <item>
      <title>Re: Create a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-string/m-p/499352#M132864</link>
      <description>&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; i=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%to&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; j=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%to&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; upcase(trim(boap&amp;amp;j)) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; boap&amp;amp;j &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;j &amp;lt; &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"*"&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; into :&lt;/FONT&gt;&lt;FONT color="#ff0000" face="Courier New" size="3"&gt;state1&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; seperated by &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"|"&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;from billplan;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;quit&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So number of rows is 4 so first time it loops 4 times and then it loops three times for&amp;nbsp; three variables all three variables are separated by * and each row is separated by |and that's how the variable State1 at the end looks like&lt;/P&gt;
&lt;P&gt;Ins*Status*Cycle|Total*Pays |Cust |Num*Disc*Early&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 02:52:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-string/m-p/499352#M132864</guid>
      <dc:creator>chennupriya</dc:creator>
      <dc:date>2018-09-27T02:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-string/m-p/499388#M132882</link>
      <description>&lt;P&gt;Did you try my program?&amp;nbsp; To me, it looks much simpler.&amp;nbsp; Do you require the final string to be placed into a macro variable?&amp;nbsp; A DATA step can easily do that.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Sep 2018 07:30:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-string/m-p/499388#M132882</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-09-27T07:30:23Z</dc:date>
    </item>
    <item>
      <title>Re: Create a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-string/m-p/499566#M132959</link>
      <description>&lt;P&gt;Hi Above code works but what if I don't know the length of the state1(length of final string ) &amp;nbsp;since I have 300 rows and each row has 4 variables ? and the string would be truncated if we don't give correct length&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help&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;</description>
      <pubDate>Thu, 27 Sep 2018 15:59:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-string/m-p/499566#M132959</guid>
      <dc:creator>chennupriya</dc:creator>
      <dc:date>2018-09-27T15:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-string/m-p/500017#M133090</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11383"&gt;@chennupriya&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Above code works but what if I don't know the length of the state1(length of final string ) &amp;nbsp;since I have 300 rows and each row has 4 variables ? and the string would be truncated if we don't give correct length&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help&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;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Know thy data.&lt;/P&gt;
&lt;P&gt;You would need to examine the number of variables and their lengths that will concatenated. For ease of calculations you can use the length(s) assigned to the variables, sum those and add one character per variable per "row" you might need to provide for a space or comma or what ever between values. Then assign that as the length of the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want an "automagic" code for such start be examining sashelp.vcolumn (or dictionary.columns if you use Proc SQL) to pull the lengths of the variables. SASHELP.Vtable (or dictionary.tables ) has the number of observations in the variable NOBS.&lt;/P&gt;
&lt;P&gt;Or use proc contents to get info.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 19:53:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-string/m-p/500017#M133090</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-09-28T19:53:37Z</dc:date>
    </item>
    <item>
      <title>Re: Create a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-string/m-p/500043#M133106</link>
      <description>&lt;P&gt;Just give a long enough length, such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;length state1 $ 20000;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also use the global option COMPRESS=YES so that if you assign extra space, that extra space won't be needed for storing the value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you transfer the value to a macro variable, use CALL SYMPUTX, not CALL SYMPUT.&amp;nbsp; That way, the extra blanks won't be transferred.&lt;/P&gt;</description>
      <pubDate>Fri, 28 Sep 2018 21:13:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-string/m-p/500043#M133106</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-09-28T21:13:20Z</dc:date>
    </item>
  </channel>
</rss>

