<?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: For Var 1 break Var2 by all data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/For-Var-1-break-Var2-by-all-data/m-p/287927#M59292</link>
    <description>&lt;P&gt;Here is an example with a small dataset.&lt;/P&gt;
&lt;P&gt;The example will have an issue if the col2 variable is blank, which is why I asked what you want to do in that case.&lt;/P&gt;
&lt;P&gt;This assumes comma is the only delimiter between the values that will be encountered, it drops the original value for column 2 and assumes that the longest of the values within column 2 is 10 characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   informat id best4. col2 $40.;
   input id col2;
datalines;
111   0
112   0
123   5401,5402
124   5401,5402,5403,5404,5406
;
run;

data want;
   set have;
   length newcol2 $ 10.;
   do i= 1 to (countw(col2));
      newcol2 = scan(col2,i);
      output;
   end;
   drop i col2;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 28 Jul 2016 19:18:39 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-07-28T19:18:39Z</dc:date>
    <item>
      <title>For Var 1 break Var2 by all data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/For-Var-1-break-Var2-by-all-data/m-p/287905#M59284</link>
      <description>&lt;P&gt;Hi guys!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am very new in SAS Base programming, I would like of ideas about the following situation:&lt;/P&gt;
&lt;P&gt;I am importing an excel spreadsheet, and on&amp;nbsp;cell 1 I have the ID and on&amp;nbsp;cell 2 multiple values separated by ','.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I need is to repeat the value for cell 1 for all the values of cell 2 in different lines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See the example below:&lt;/P&gt;
&lt;P&gt;What I have&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/4316i68CED7E4BC4BC171/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Exemplo.PNG" title="Exemplo.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I need&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/4317iF0278847F9A65925/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Exemplo2.PNG" title="Exemplo2.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any ideas?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LeoGaller&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2016 18:27:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/For-Var-1-break-Var2-by-all-data/m-p/287905#M59284</guid>
      <dc:creator>leogaller</dc:creator>
      <dc:date>2016-07-28T18:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: For Var 1 break Var2 by all data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/For-Var-1-break-Var2-by-all-data/m-p/287916#M59288</link>
      <description>&lt;P&gt;Have already brought the data into SAS? That may sound silly but we have such things sometimes.&lt;/P&gt;
&lt;P&gt;Some additional things to consider:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; Do you need the original variable with multiple values when done?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; Are there any other variables to consider?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; What to do if the column 2 variable is blank? Should there be any output (remove the record) or have the line basically output as is?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And it is difficult to read the picture so an example data, preferably in the form of a datast would help for us to have something to actually work with. This link has&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; instructions on how to turn a dataset into data step code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, the image of your example data seems to show a period between the values on the third row. Can that possibly occur?.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2016 19:00:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/For-Var-1-break-Var2-by-all-data/m-p/287916#M59288</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-07-28T19:00:48Z</dc:date>
    </item>
    <item>
      <title>Re: For Var 1 break Var2 by all data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/For-Var-1-break-Var2-by-all-data/m-p/287927#M59292</link>
      <description>&lt;P&gt;Here is an example with a small dataset.&lt;/P&gt;
&lt;P&gt;The example will have an issue if the col2 variable is blank, which is why I asked what you want to do in that case.&lt;/P&gt;
&lt;P&gt;This assumes comma is the only delimiter between the values that will be encountered, it drops the original value for column 2 and assumes that the longest of the values within column 2 is 10 characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   informat id best4. col2 $40.;
   input id col2;
datalines;
111   0
112   0
123   5401,5402
124   5401,5402,5403,5404,5406
;
run;

data want;
   set have;
   length newcol2 $ 10.;
   do i= 1 to (countw(col2));
      newcol2 = scan(col2,i);
      output;
   end;
   drop i col2;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Jul 2016 19:18:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/For-Var-1-break-Var2-by-all-data/m-p/287927#M59292</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-07-28T19:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: For Var 1 break Var2 by all data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/For-Var-1-break-Var2-by-all-data/m-p/287933#M59294</link>
      <description>&lt;P&gt;Hi Ballardw!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Have already brought the data into SAS?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Yes, the data is already in SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Do you need the original variable with multiple values when done?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Yes, I need, because later I will join the result dataset with another one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Are there any other variables to consider?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Not now. I just need these two right now.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;What to do if the column 2 variable is blank?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;There is &lt;STRONG&gt;no&lt;/STRONG&gt; blank values in variable 2 because I treated that situation when I was importing the data into SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Should there be any output (remove the record) or have the line basically output as is?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Yes, I need an output just with the 2 variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;BTW, the image of your example data seems to show a period between the values on the third row. Can that possibly occur?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Actually that is a comma, I want to break the data using that comma.&lt;/P&gt;
&lt;P&gt;For example, write the value o var1, if var2 has two values separated by comma, I want to repeat var1 for each value in var2 that are separated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your attention and support! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the code for sample data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample_data;
	input number $ PreExecution $20.;
	datalines;
	5044 5297,5367
	5055 5297,5367,5467
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;LeoGaller&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2016 19:35:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/For-Var-1-break-Var2-by-all-data/m-p/287933#M59294</guid>
      <dc:creator>leogaller</dc:creator>
      <dc:date>2016-07-28T19:35:57Z</dc:date>
    </item>
    <item>
      <title>Re: For Var 1 break Var2 by all data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/For-Var-1-break-Var2-by-all-data/m-p/287937#M59297</link>
      <description>Many thanks Ballardw, your explanation was perfect! \o/</description>
      <pubDate>Thu, 28 Jul 2016 19:44:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/For-Var-1-break-Var2-by-all-data/m-p/287937#M59297</guid>
      <dc:creator>leogaller</dc:creator>
      <dc:date>2016-07-28T19:44:15Z</dc:date>
    </item>
  </channel>
</rss>

