<?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: Data manipulation add vertical a value separated by comma in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-manipulation-add-vertical-a-value-separated-by-comma/m-p/912723#M359779</link>
    <description>&lt;P&gt;Someone appears to be thinking like a spreadsheet. If A1 is supposed to be the value of &lt;STRONG&gt;variable&lt;/STRONG&gt; A in the first observation then you have a data set that looks like:&lt;/P&gt;
&lt;PRE&gt;data have;
   input a b c:$15.;
datalines;
1 11 allo,okay
2 12 .
3 13 z,d,h
;
&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;ure please attempt to provide existing data in the form of a working data step pasted into a text box opened on the forum using the &amp;lt;/&amp;gt; icon that appears above the main message window. The text box is important because the forum software will reformat pasted text and may result in code that will not run.&lt;/P&gt;
&lt;P&gt;The above assumes none of your C values have spaces in them and a space can be used to delimit the data for reading with list input and &lt;STRONG&gt;assumes &lt;/STRONG&gt;that A and B are numeric values since you did not specify in any way whether they are numeric or character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Such can be done with :&lt;/P&gt;
&lt;PRE&gt;data want (rename=(cword=c));
  set have;
  length cword $ 15;
  words=countw(c,',');
  if words=0 then output;
  else do i=1 to words;
   cword = scan(c,i,',');
   output;
  end;
  drop i words c;
run;
&lt;/PRE&gt;
&lt;P&gt;Because we need the entire value of C someplace and you want different values apparently in the output we will need to rename the C at some time. The above code renames the single value variable on the output set to the name of C.&lt;/P&gt;
&lt;P&gt;The OUTPUT instruction writes to the output set when encountered. So you can specify conditions and values when using such. In this case we determine of the C value has any elements counting values separated by commas. If none, then write out immediately. Otherwise extract each "word" using the SCAN function and then write out one at a time. The other variable values, A and B are not manipulated so the starting value gets written out repeatedly for value in C.&lt;/P&gt;</description>
    <pubDate>Tue, 23 Jan 2024 15:45:31 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2024-01-23T15:45:31Z</dc:date>
    <item>
      <title>Data manipulation add vertical a value separated by comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-manipulation-add-vertical-a-value-separated-by-comma/m-p/912713#M359778</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Please help with this&lt;/STRONG&gt;&lt;BR /&gt;how can you transfer data from situation 1 to situation 2?&lt;BR /&gt;data situation 1:&lt;BR /&gt;column A : A1 = 1 ; A2 = 2 ; A3=3&lt;BR /&gt;column B : B1 = 11 ; B2 = 12 ; B3 = 13&lt;BR /&gt;column C : C1 = allo , okay ; C2 = ; C3 = z , d , h&lt;BR /&gt;data situation 2:&lt;BR /&gt;column A : A1 = 1;&amp;nbsp; A2 = 1;&amp;nbsp; A3 = 2;&amp;nbsp; A4 = 3; &amp;nbsp; A5 = 3;&amp;nbsp; A6 = 3&lt;BR /&gt;column B : B1 = 11; B2 = 11; B3 = 12; B4 = 13; B5 = 13; B6 = 13&lt;BR /&gt;column C : C1 = allo;&amp;nbsp; C2 = okay;&amp;nbsp; C3 = ;&amp;nbsp; C4 = z ;&amp;nbsp; C5 = d;&amp;nbsp; B6 = h&lt;/P&gt;&lt;P&gt;note that C2 is when situation 1 is empty and C3 is when situation 2 is empty&lt;BR /&gt;so data input is situation 1 and data output is situation 2&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2024 15:14:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-manipulation-add-vertical-a-value-separated-by-comma/m-p/912713#M359778</guid>
      <dc:creator>melassiri</dc:creator>
      <dc:date>2024-01-23T15:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: Data manipulation add vertical a value separated by comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-manipulation-add-vertical-a-value-separated-by-comma/m-p/912723#M359779</link>
      <description>&lt;P&gt;Someone appears to be thinking like a spreadsheet. If A1 is supposed to be the value of &lt;STRONG&gt;variable&lt;/STRONG&gt; A in the first observation then you have a data set that looks like:&lt;/P&gt;
&lt;PRE&gt;data have;
   input a b c:$15.;
datalines;
1 11 allo,okay
2 12 .
3 13 z,d,h
;
&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;ure please attempt to provide existing data in the form of a working data step pasted into a text box opened on the forum using the &amp;lt;/&amp;gt; icon that appears above the main message window. The text box is important because the forum software will reformat pasted text and may result in code that will not run.&lt;/P&gt;
&lt;P&gt;The above assumes none of your C values have spaces in them and a space can be used to delimit the data for reading with list input and &lt;STRONG&gt;assumes &lt;/STRONG&gt;that A and B are numeric values since you did not specify in any way whether they are numeric or character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Such can be done with :&lt;/P&gt;
&lt;PRE&gt;data want (rename=(cword=c));
  set have;
  length cword $ 15;
  words=countw(c,',');
  if words=0 then output;
  else do i=1 to words;
   cword = scan(c,i,',');
   output;
  end;
  drop i words c;
run;
&lt;/PRE&gt;
&lt;P&gt;Because we need the entire value of C someplace and you want different values apparently in the output we will need to rename the C at some time. The above code renames the single value variable on the output set to the name of C.&lt;/P&gt;
&lt;P&gt;The OUTPUT instruction writes to the output set when encountered. So you can specify conditions and values when using such. In this case we determine of the C value has any elements counting values separated by commas. If none, then write out immediately. Otherwise extract each "word" using the SCAN function and then write out one at a time. The other variable values, A and B are not manipulated so the starting value gets written out repeatedly for value in C.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jan 2024 15:45:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-manipulation-add-vertical-a-value-separated-by-comma/m-p/912723#M359779</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-01-23T15:45:31Z</dc:date>
    </item>
    <item>
      <title>Re: Data manipulation add vertical a value separated by comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-manipulation-add-vertical-a-value-separated-by-comma/m-p/912841#M359811</link>
      <description>&lt;P&gt;thank you for your help. I appreciate that&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2024 15:28:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-manipulation-add-vertical-a-value-separated-by-comma/m-p/912841#M359811</guid>
      <dc:creator>melassiri</dc:creator>
      <dc:date>2024-01-24T15:28:14Z</dc:date>
    </item>
  </channel>
</rss>

