<?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 create new records with variables containing multiple values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-new-records-with-variables-containing-multiple/m-p/685033#M207705</link>
    <description>&lt;P&gt;So is the logic that you want to implement something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Create a record with text from column A before the comma, and then another record with text from column A after the comma but before the next comma, and so on splitting at every comma, all such records having the same value that was in column B?&lt;/P&gt;</description>
    <pubDate>Fri, 18 Sep 2020 16:51:16 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-09-18T16:51:16Z</dc:date>
    <item>
      <title>how to create new records with variables containing multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-new-records-with-variables-containing-multiple/m-p/685027#M207702</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a variable "Labels" with some having multiple values (which is identified by ",".)&lt;/P&gt;&lt;P&gt;I need to separate these values and create new records along with variable "Total Twitter Impressions".&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;eg.&lt;/P&gt;&lt;P&gt;raw data&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HitmonTran_0-1600445478364.png" style="width: 685px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49538i12E1AD5BE808136A/image-dimensions/685x167?v=v2" width="685" height="167" role="button" title="HitmonTran_0-1600445478364.png" alt="HitmonTran_0-1600445478364.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;want data:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HitmonTran_1-1600445653795.png" style="width: 712px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49539iFE13AFDB049F2467/image-dimensions/712x267?v=v2" width="712" height="267" role="button" title="HitmonTran_1-1600445653795.png" alt="HitmonTran_1-1600445653795.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you all&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2020 16:16:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-new-records-with-variables-containing-multiple/m-p/685027#M207702</guid>
      <dc:creator>HitmonTran</dc:creator>
      <dc:date>2020-09-18T16:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: how to create new records with variables containing multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-new-records-with-variables-containing-multiple/m-p/685033#M207705</link>
      <description>&lt;P&gt;So is the logic that you want to implement something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Create a record with text from column A before the comma, and then another record with text from column A after the comma but before the next comma, and so on splitting at every comma, all such records having the same value that was in column B?&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2020 16:51:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-new-records-with-variables-containing-multiple/m-p/685033#M207705</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-18T16:51:16Z</dc:date>
    </item>
    <item>
      <title>Re: how to create new records with variables containing multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-new-records-with-variables-containing-multiple/m-p/685041#M207709</link>
      <description>&lt;P&gt;I am not going to retype anything to create data and can't code from pictures.&lt;/P&gt;
&lt;P&gt;This example creates an example data set with pretty trivial data to do similar to what you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
   input string :$15. value;
datalines;
a       15
a,b,c   25
b,c,d   0
b,d     5
;

data want;
   set have;
   length newstring $ 10;
   do i= 1 to countw(string,',');
      newstring = scan(string,i,',');
      output;
   end;
   keep newstring value;
run;


&lt;/PRE&gt;
&lt;P&gt;Key elements: The length of the Newstring (or what ever you want to name your new variable) needs to be long enough to hold the longest expected value.&lt;/P&gt;
&lt;P&gt;The ',' in the COUNTW and SCAN functions is so anything other than a comma is not treated as a boundary between values.&lt;/P&gt;
&lt;P&gt;The explicit output statement writes the output for each time through the Do loop, which is counting the number of comma delimited values with Scan selecting the matching value.&lt;/P&gt;
&lt;P&gt;The Keep is retain the specific variables. You may or may not want to keep your original variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2020 17:16:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-new-records-with-variables-containing-multiple/m-p/685041#M207709</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-18T17:16:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to create new records with variables containing multiple values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-create-new-records-with-variables-containing-multiple/m-p/685065#M207716</link>
      <description>thank you very much! this is awesome&lt;BR /&gt;</description>
      <pubDate>Fri, 18 Sep 2020 18:47:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-create-new-records-with-variables-containing-multiple/m-p/685065#M207716</guid>
      <dc:creator>HitmonTran</dc:creator>
      <dc:date>2020-09-18T18:47:44Z</dc:date>
    </item>
  </channel>
</rss>

