<?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 parsing a string using data as new variable name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-string-using-data-as-new-variable-name/m-p/298726#M62864</link>
    <description>&lt;P&gt;I need some help with what I think is simple but I cannot seem to get it to work or find anyone else posting this...I can parse a text string by array but I want to identify the number of the parsed string in the new variable name (match them up).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have lots of data fields that have selected more than one option and they are separated by commas. Since I have alot of these fields in my data I was hoping to find a less&amp;nbsp;manual way of doing this. I want data to correspond to the variable name. Obviously, it is a character variable source but the source1-source8 I want as numeric.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;variable source has values&lt;/P&gt;&lt;P&gt;1,3,7&lt;/P&gt;&lt;P&gt;1,2,5&lt;/P&gt;&lt;P&gt;1,2,3,6,7&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2,8&lt;/P&gt;&lt;P&gt;and so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I want to separate by commas data into 8 variables (source1, source2...source8). But I want the '1,3,7, to show up in source1 as '1', source3 as '3', source7 as '7' and not source1 as '1', source2 as '3', and source3 as '7'.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks, JJ&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 15 Sep 2016 17:16:49 GMT</pubDate>
    <dc:creator>jljones</dc:creator>
    <dc:date>2016-09-15T17:16:49Z</dc:date>
    <item>
      <title>parsing a string using data as new variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-string-using-data-as-new-variable-name/m-p/298726#M62864</link>
      <description>&lt;P&gt;I need some help with what I think is simple but I cannot seem to get it to work or find anyone else posting this...I can parse a text string by array but I want to identify the number of the parsed string in the new variable name (match them up).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have lots of data fields that have selected more than one option and they are separated by commas. Since I have alot of these fields in my data I was hoping to find a less&amp;nbsp;manual way of doing this. I want data to correspond to the variable name. Obviously, it is a character variable source but the source1-source8 I want as numeric.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;variable source has values&lt;/P&gt;&lt;P&gt;1,3,7&lt;/P&gt;&lt;P&gt;1,2,5&lt;/P&gt;&lt;P&gt;1,2,3,6,7&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2,8&lt;/P&gt;&lt;P&gt;and so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;I want to separate by commas data into 8 variables (source1, source2...source8). But I want the '1,3,7, to show up in source1 as '1', source3 as '3', source7 as '7' and not source1 as '1', source2 as '3', and source3 as '7'.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks, JJ&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 17:16:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-a-string-using-data-as-new-variable-name/m-p/298726#M62864</guid>
      <dc:creator>jljones</dc:creator>
      <dc:date>2016-09-15T17:16:49Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a string using data as new variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-string-using-data-as-new-variable-name/m-p/298728#M62865</link>
      <description>&lt;P&gt;Do you know ahead of time that you will have 8 values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, declare an array and use scan to parse out the text.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;COUNTW - Number of items in list&lt;/P&gt;
&lt;P&gt;SCAN - extracts specific item&lt;/P&gt;
&lt;P&gt;INPUT - convert char to numeric&lt;/P&gt;
&lt;P&gt;SOURCE(num) -&amp;gt; Array to assign value using it as an index.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array source(8) source1-source8;

n_items=countw(string);

do i=1 to n_items;
x=scan(string, i);
x_num=input(x, 8.);
source(x_num)=x_num;
end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you don't know how many values you'll have ahead of time this doesn't work as well. Depending on the size of the data, its probably easiest to figure out the maximum number and use that in this process.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 17:21:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-a-string-using-data-as-new-variable-name/m-p/298728#M62865</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-09-15T17:21:29Z</dc:date>
    </item>
    <item>
      <title>Re: parsing a string using data as new variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/parsing-a-string-using-data-as-new-variable-name/m-p/298731#M62868</link>
      <description>&lt;P&gt;Thank you Reeza! I will know the items since it was a category (check all apply thing) and it worked like a charm. Data sets are not huge.&amp;nbsp;I will use this often. Yeehaw! JJ&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2016 17:33:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/parsing-a-string-using-data-as-new-variable-name/m-p/298731#M62868</guid>
      <dc:creator>jljones</dc:creator>
      <dc:date>2016-09-15T17:33:06Z</dc:date>
    </item>
  </channel>
</rss>

