<?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: parsing a character string into new variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/129191#M260483</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you be more specific?&amp;nbsp; Also, note that &lt;STRONG&gt;orig_var&lt;/STRONG&gt; is one variable in a SAS dataset that has like 200 other variables.&amp;nbsp; It's not a raw data file for me to import.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 04 Sep 2013 17:19:12 GMT</pubDate>
    <dc:creator>Total_FREQ</dc:creator>
    <dc:date>2013-09-04T17:19:12Z</dc:date>
    <item>
      <title>parsing a character string into new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/129189#M260481</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hey All!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a character variable of varying lengths that I want to separate into separate variables.&amp;nbsp; The variable always follows the following pattern - AA.AA.AA.AA.AA (2 characters then a period, 2 characters then a period, etc) - and each "AA" signifies a unique code I need to have separated for further analysis.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example of what it looks like now:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 127px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl63" height="20" width="127"&gt;&lt;STRONG&gt;orig_var&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;AA.4F.9U.EB&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;E5.U9&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;GB.D2.4F.EB.AA.M2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;T4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;YY.4D.U9&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How I'd like for it to look:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 529px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD class="xl65" height="20" width="127"&gt;&lt;STRONG&gt;orig_var&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl65" width="67"&gt;&lt;STRONG&gt;new_var1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl65" width="67"&gt;&lt;STRONG&gt;new_var2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl65" width="67"&gt;&lt;STRONG&gt;new_var3&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl65" width="67"&gt;&lt;STRONG&gt;new_var4&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl65" width="67"&gt;&lt;STRONG&gt;new_var5&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD class="xl65" width="67"&gt;&lt;STRONG&gt;new_var6&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;AA.4F.9U.EB&lt;/TD&gt;&lt;TD&gt;AA&lt;/TD&gt;&lt;TD class="xl66"&gt;4F&lt;/TD&gt;&lt;TD&gt;9U&lt;/TD&gt;&lt;TD&gt;EB&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;E5.U9&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;GB.D2.4F.EB.AA.M2&lt;/TD&gt;&lt;TD&gt;GB&lt;/TD&gt;&lt;TD&gt;D2&lt;/TD&gt;&lt;TD&gt;4F&lt;/TD&gt;&lt;TD&gt;EB&lt;/TD&gt;&lt;TD&gt;AA&lt;/TD&gt;&lt;TD&gt;M2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;T4&lt;/TD&gt;&lt;TD&gt;T4&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;YY.4D.U9&lt;/TD&gt;&lt;TD&gt;YY&lt;/TD&gt;&lt;TD&gt;4D&lt;/TD&gt;&lt;TD&gt;U9&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any thoughts on how to code this to parse those 2-char codes?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;Erice&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Sep 2013 16:43:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/129189#M260481</guid>
      <dc:creator>Total_FREQ</dc:creator>
      <dc:date>2013-09-04T16:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a character string into new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/129190#M260482</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Specify the period as your delimiter.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Sep 2013 16:48:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/129190#M260482</guid>
      <dc:creator>Fugue</dc:creator>
      <dc:date>2013-09-04T16:48:14Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a character string into new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/129191#M260483</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you be more specific?&amp;nbsp; Also, note that &lt;STRONG&gt;orig_var&lt;/STRONG&gt; is one variable in a SAS dataset that has like 200 other variables.&amp;nbsp; It's not a raw data file for me to import.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Sep 2013 17:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/129191#M260483</guid>
      <dc:creator>Total_FREQ</dc:creator>
      <dc:date>2013-09-04T17:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a character string into new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/129192#M260484</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That changes things then. A simple approach would be to use something like the scan function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;newvar1=scan(orig_var, 1, '.');&lt;/P&gt;&lt;P&gt;newvar2=scan(orig_var, 2, '.');&lt;/P&gt;&lt;P&gt;etc&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Sep 2013 17:26:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/129192#M260484</guid>
      <dc:creator>Fugue</dc:creator>
      <dc:date>2013-09-04T17:26:11Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a character string into new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/129193#M260485</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you know the max number of variables? if so loop using the scan function and . as your delimiter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;array parsed_vars(*) new_var1-new_var6;&lt;/P&gt;&lt;P&gt;i=1;&lt;/P&gt;&lt;P&gt;do while(scan(str, i, ".") ne "");&lt;/P&gt;&lt;P&gt;parsed_vars(i) =scan(str, i, ".");&lt;/P&gt;&lt;P&gt;i+1;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Sep 2013 17:27:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/129193#M260485</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-09-04T17:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a character string into new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/129194#M260486</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Reeza --&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That worked except that there was a numeric vs character mismatch betweent he array variables and the orig_var pieces.&amp;nbsp; When I added &lt;STRONG&gt;_char_&lt;/STRONG&gt; at the end of the array line, it work PERFECTLY.&amp;nbsp; I was attempting some sort of array thing but just couldn't get it quite right on my own.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;THANKS!!&lt;/P&gt;&lt;P&gt;Eric&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Sep 2013 17:40:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/129194#M260486</guid>
      <dc:creator>Total_FREQ</dc:creator>
      <dc:date>2013-09-04T17:40:09Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a character string into new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/129195#M260487</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you should add the dollar sign instead of _char_. That would add in all the character variables to your array and you could potentially overwrite a variable if you had more than 6 variables in your variable that was to be parsed. In fact, it may not be a bad idea to explicitly declare the array length rather than use the * method.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;array parsed_vars(6) $&amp;nbsp; new_var1-new_var6;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Sep 2013 17:54:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/129195#M260487</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-09-04T17:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a character string into new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/129196#M260488</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you don't know the max. number of elements in orig_var, it can be found and stored in a macro variable by proc sql. The number can then be used to dynamically create the required number of new variables in the output data set:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;&amp;nbsp; select max(count(orig_var,'.'))+1 into :maxelements from have;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;data want (drop=i); set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; array parsed_vars $ 2 new_var1-new_var%eval(&amp;amp;maxelements);&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i = 1 to &amp;amp;maxelements;&lt;/P&gt;&lt;P&gt;&amp;nbsp; parsed_vars{i} = scan(orig_var,i,'.');&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Jan 2015 17:51:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/129196#M260488</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2015-01-28T17:51:59Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a character string into new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/129197#M260489</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Another low-maintenance dynamic option can be Proc Transpose:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; var &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: teal; background: white;"&gt;$40.&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;length&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; svar $ &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;2&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; i=&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;by&lt;/SPAN&gt; &lt;STRONG style="color: teal; background: white; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;until&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; (missing(svar));&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; svar=scan(var,i,&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: purple; background: white;"&gt;'.'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;if&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;not&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; missing(svar) &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;then&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;output&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;cards&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;AA.4F.9U.EB&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;E5.U9&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;GB.D2.4F.EB.AA.M2&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;T4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: #FFFFC0;"&gt;YY.4D.U9&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;sort&lt;/STRONG&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;data&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;=have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;by&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; var;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;transpose&lt;/STRONG&gt; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;data&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;=have &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;out&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;=want (&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;drop&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;=_name_) &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;prefix&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;=new_var;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;by&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; var;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; color: blue; background: white;"&gt;var&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt; svar;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 28 Jan 2015 18:19:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/129197#M260489</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2015-01-28T18:19:14Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a character string into new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/285558#M260490</link>
      <description>&lt;P&gt;An alternative to Reeza's solution is to use a for-loop rather than a while (for people that don't trust while loops):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    array parsed_vars(*) new_var1-new_var6;

    do i = 1 to 6;
        parsed_vars(i) =scan(str, i, ".");
    end;

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The 6 can be redefined as a macro variable. In my code I have a length statement before the array statement, I do not know whether it works for al data without the length statement.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2016 16:22:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/285558#M260490</guid>
      <dc:creator>CR204</dc:creator>
      <dc:date>2016-07-19T16:22:20Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a character string into new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/285583#M260491</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/95328"&gt;@CR204﻿&lt;/a&gt;, curious what you mean by not trusting WHILE loops?&amp;nbsp; They've always been trustworthy to me.&amp;nbsp; I suppose one risk they bring is that you can accidentally write an infinite loop.&amp;nbsp; But to me, they're still worthy of trust and are a useful tool.&amp;nbsp; Are you thinking of other concerns?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2016 17:29:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/285583#M260491</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2016-07-19T17:29:17Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a character string into new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/285585#M260492</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19879"&gt;@Quentin﻿&lt;/a&gt; While loops can be useful, but I dislike using them when a simple for loop would work. The "don't trust" part should be read with a wink. &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2016 17:35:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/285585#M260492</guid>
      <dc:creator>CR204</dc:creator>
      <dc:date>2016-07-19T17:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a character string into new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/433225#M260495</link>
      <description>&lt;P&gt;* Nice ! ;&lt;BR /&gt;* My minor edits:&lt;BR /&gt;* 1. no PRoc sort needed. ;&lt;BR /&gt;* 2. use ID statement ;&lt;BR /&gt;proc transpose data=have out=want (drop=_name_) prefix=var;&lt;BR /&gt;by var notsorted;&lt;BR /&gt;id i;&lt;BR /&gt;var svar;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 18:46:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/433225#M260495</guid>
      <dc:creator>Quinn</dc:creator>
      <dc:date>2018-02-01T18:46:02Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a character string into new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/436296#M260496</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used your code which worked well in my project.&amp;nbsp; Today, however, I am getting an error (Array subscript out of range at line 29, column 1).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my code:&amp;nbsp; Not sure why it worked last week and not working today.&amp;nbsp; Any help would be appreciated!&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Parsed_Topics;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; have;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;array&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; PARSED_VARS(*)$&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;100&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; Topic1-Topic12;&lt;/FONT&gt;&lt;/P&gt;&lt;P&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 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 color="#0000ff" face="Courier New" size="3"&gt;while&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(scan(TrainingTopic, i, ";") ne "");&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PARSED_VARS(i) =scan(TrainingTopic, i, ";");&lt;/P&gt;&lt;P&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 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="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 18:10:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/436296#M260496</guid>
      <dc:creator>mstergia</dc:creator>
      <dc:date>2018-02-12T18:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a character string into new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/436298#M260497</link>
      <description>&lt;P&gt;&lt;SPAN&gt;See if string variable TrainingTopic contains more than 12 delimiters ':' - 12 is the array upbound.&amp;nbsp; &amp;nbsp;Hop it helps.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;L.L&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 18:20:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/436298#M260497</guid>
      <dc:creator>Quinn</dc:creator>
      <dc:date>2018-02-12T18:20:06Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a character string into new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/436301#M260498</link>
      <description>&lt;P&gt;Thanks Quinn; I am being told that 12 is the maximum.&amp;nbsp; However, what if one didn`t know the max?&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2018 18:24:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/436301#M260498</guid>
      <dc:creator>mstergia</dc:creator>
      <dc:date>2018-02-12T18:24:46Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a character string into new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/436929#M260499</link>
      <description>&lt;P&gt;Wondering, what does the * do rather than putting the max # of observations in the () in :&amp;nbsp; array parsed_vars(*) new_var1-new_var6;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Trying to understand the diff between putting parsed_vars(*) vs. parsed_vars(6)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, what if you didn`t know the max # of observations?&amp;nbsp; what would you do in that case if you only wanted the first 6?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2018 23:38:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/436929#M260499</guid>
      <dc:creator>mstergia</dc:creator>
      <dc:date>2018-02-13T23:38:31Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a character string into new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/437280#M260500</link>
      <description>Thanks Quinn - that was exactly the problem. What if one didn`t know the array upbound. Is there a way to write the code when you don`t know what that # is?</description>
      <pubDate>Wed, 14 Feb 2018 19:15:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/437280#M260500</guid>
      <dc:creator>mstergia</dc:creator>
      <dc:date>2018-02-14T19:15:04Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a character string into new variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/437290#M260501</link>
      <description>&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;1. use COUNTC() function.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;2. use the variable prefix as the array name.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;Hope it helps.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;L.L.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;proc sql;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;select max(&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;countc(&lt;SPAN&gt;TrainingTopic,';'))+1&amp;nbsp; into: max_ct from ...;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;&lt;SPAN&gt;data ... ;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;&lt;SPAN&gt;...&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;array&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt; Topic&lt;/SPAN&gt;(&amp;amp;max_ct) $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;100&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&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;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Feb 2018 19:40:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-a-character-string-into-new-variables/m-p/437290#M260501</guid>
      <dc:creator>Quinn</dc:creator>
      <dc:date>2018-02-14T19:40:02Z</dc:date>
    </item>
  </channel>
</rss>

