<?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: Splitting one variable into multiple based on criteria from another variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Splitting-one-variable-into-multiple-based-on-criteria-from/m-p/308768#M61201</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input X $ Z;
   datalines;
A 4. 
A 3  
B 7  
A 5  
B 8 
B 8.5
;

Data want;
  set have;
       if   x='A' then Z1=Z; 
       else x='B' then Z2=Z;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 02 Nov 2016 15:04:37 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2016-11-02T15:04:37Z</dc:date>
    <item>
      <title>Splitting one variable into multiple based on criteria from another variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Splitting-one-variable-into-multiple-based-on-criteria-from/m-p/308762#M61198</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a question which is intuitively not very difficult, but I cannot seem to find a way to do this in SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two variables: variable X (categorical: levels A and B), and a continious variable Z (numeric).&lt;/P&gt;&lt;P&gt;I want to create&amp;nbsp;two new variables out of variable Z, with values that depend on the level of X (A or B).&lt;/P&gt;&lt;P&gt;See the accompanying table. Someone knows the appropriate syntax? Thanks a lot in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;X&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Z&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Z1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;Z2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;A&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;4.2&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;4.2&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;A&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;3&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;3&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;B&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;7&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;7&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;A&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;5&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;5&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;B&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;8&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;8&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;B&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;8.5&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;8.5&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 02 Nov 2016 14:42:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Splitting-one-variable-into-multiple-based-on-criteria-from/m-p/308762#M61198</guid>
      <dc:creator>Marjolein</dc:creator>
      <dc:date>2016-11-02T14:42:38Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting one variable into multiple based on criteria from another variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Splitting-one-variable-into-multiple-based-on-criteria-from/m-p/308766#M61199</link>
      <description>&lt;P&gt;I understand that Z1 and Z2 are two new variables to create:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if x='A' then Z1=Z; else&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if x='B' then Z2=Z;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2016 14:55:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Splitting-one-variable-into-multiple-based-on-criteria-from/m-p/308766#M61199</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-02T14:55:30Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting one variable into multiple based on criteria from another variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Splitting-one-variable-into-multiple-based-on-criteria-from/m-p/308767#M61200</link>
      <description>&lt;P&gt;It looks like you want something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if X = 'A' Then Z1 = z;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if X='B' then Z2 = z;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: If you have a large number of values of X to consider there are different approaches that may work such as use of the IN comparison if the same thing is done for multiple values or a different structure called SELECT if you have multiple values and each generates a different output.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2016 14:56:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Splitting-one-variable-into-multiple-based-on-criteria-from/m-p/308767#M61200</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-02T14:56:48Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting one variable into multiple based on criteria from another variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Splitting-one-variable-into-multiple-based-on-criteria-from/m-p/308768#M61201</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   input X $ Z;
   datalines;
A 4. 
A 3  
B 7  
A 5  
B 8 
B 8.5
;

Data want;
  set have;
       if   x='A' then Z1=Z; 
       else x='B' then Z2=Z;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Nov 2016 15:04:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Splitting-one-variable-into-multiple-based-on-criteria-from/m-p/308768#M61201</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2016-11-02T15:04:37Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting one variable into multiple based on criteria from another variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Splitting-one-variable-into-multiple-based-on-criteria-from/m-p/308771#M61202</link>
      <description>&lt;P&gt;To me, the quesiton is why. &amp;nbsp;Currently you have a dataset with two columns, one indicates data position (i.e a where=a would show all z1 for instance), and one is the result. &amp;nbsp;There are no missing elements. &amp;nbsp;What you are asking for is a dataset which is twice as big - 4 variables - with various missing elements, but doesn't actually add anything to the data. &amp;nbsp;So why bother, its just taking more room but without any benefit.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2016 15:28:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Splitting-one-variable-into-multiple-based-on-criteria-from/m-p/308771#M61202</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-11-02T15:28:05Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting one variable into multiple based on criteria from another variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Splitting-one-variable-into-multiple-based-on-criteria-from/m-p/309219#M61233</link>
      <description>&lt;P&gt;I understand your point. The reason I want to do it, is because they should really represent two distinct variables. Therefore, I really prefer to have them in seperate columns, rather than using the BY statement all the time. Or maybe my mind is rather unlogical...&lt;/P&gt;</description>
      <pubDate>Fri, 04 Nov 2016 10:18:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Splitting-one-variable-into-multiple-based-on-criteria-from/m-p/309219#M61233</guid>
      <dc:creator>Marjolein</dc:creator>
      <dc:date>2016-11-04T10:18:52Z</dc:date>
    </item>
  </channel>
</rss>

