<?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 combine values from multipe variables into one variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-combine-values-from-multipe-variables-into-one-variable/m-p/917619#M361454</link>
    <description>thanks for the quick response, I think that should work but now I'm having problems with the array statement. The variable names aren't really sequential as in the example (var1- var5). I updated my post with the new variables. Could you please help me? Thank you</description>
    <pubDate>Fri, 23 Feb 2024 17:38:05 GMT</pubDate>
    <dc:creator>HitmonTran</dc:creator>
    <dc:date>2024-02-23T17:38:05Z</dc:date>
    <item>
      <title>how to combine values from multipe variables into one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-combine-values-from-multipe-variables-into-one-variable/m-p/917614#M361451</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data set that contains about ~40 variables. But for simplicity I'll do 5 variables in this example.&lt;/P&gt;&lt;P&gt;Basically if 1 of the 5 variable has a value, the others are missing.&amp;nbsp; How do I create one variable containing all values across the 5 variables?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;have: &lt;/STRONG&gt;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;subject ID&lt;/TD&gt;&lt;TD&gt;P_00_05&lt;/TD&gt;&lt;TD&gt;P_71_80&lt;/TD&gt;&lt;TD&gt;P_141_50&lt;/TD&gt;&lt;TD&gt;P_181_90&lt;/TD&gt;&lt;TD&gt;P_291_00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;T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&gt;4&lt;/TD&gt;&lt;TD&gt;ee&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;ee&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;dd&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;bb&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;cc&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;aa&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 23 Feb 2024 17:36:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-combine-values-from-multipe-variables-into-one-variable/m-p/917614#M361451</guid>
      <dc:creator>HitmonTran</dc:creator>
      <dc:date>2024-02-23T17:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: how to combine values from multipe variables into one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-combine-values-from-multipe-variables-into-one-variable/m-p/917617#M361453</link>
      <description>&lt;P&gt;If the variables are all character something like this should work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   array v (*) var1 - var5;
   newvar = cats( of v(*));
run;&lt;/PRE&gt;
&lt;P&gt;Caveat: you will want to define the LENGTH of the Newvar to hold the longest expected value. Otherwise it would be set the length of the first result which could truncate values.&lt;/P&gt;
&lt;P&gt;The array is basically just to allow some shorthand and avoid listing multiple variables. If the array is defined with 10, 50 or a 100 variables the only difference would be in the Array definition.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2024 17:32:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-combine-values-from-multipe-variables-into-one-variable/m-p/917617#M361453</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-02-23T17:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: how to combine values from multipe variables into one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-combine-values-from-multipe-variables-into-one-variable/m-p/917619#M361454</link>
      <description>thanks for the quick response, I think that should work but now I'm having problems with the array statement. The variable names aren't really sequential as in the example (var1- var5). I updated my post with the new variables. Could you please help me? Thank you</description>
      <pubDate>Fri, 23 Feb 2024 17:38:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-combine-values-from-multipe-variables-into-one-variable/m-p/917619#M361454</guid>
      <dc:creator>HitmonTran</dc:creator>
      <dc:date>2024-02-23T17:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: how to combine values from multipe variables into one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-combine-values-from-multipe-variables-into-one-variable/m-p/917624#M361455</link>
      <description>&lt;P&gt;If the names are not sequential, but the variables are sequential when you look at your SAS data set, then this will work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;array v (*) P_00_05--P_291_00;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note the double-dash.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the variable names are not sequential in the data set, then you will have to type them yourself. (maybe there's an exception if they all have names that begin with P_ and then followed only by digits and underscore, then you could use P_: or PROC SQL to determines the names and you would not have to type the names yourself)&lt;/P&gt;</description>
      <pubDate>Fri, 23 Feb 2024 17:56:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-combine-values-from-multipe-variables-into-one-variable/m-p/917624#M361455</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-02-23T17:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: how to combine values from multipe variables into one variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-combine-values-from-multipe-variables-into-one-variable/m-p/917625#M361456</link>
      <description>Thanks it worked!</description>
      <pubDate>Fri, 23 Feb 2024 17:54:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-combine-values-from-multipe-variables-into-one-variable/m-p/917625#M361456</guid>
      <dc:creator>HitmonTran</dc:creator>
      <dc:date>2024-02-23T17:54:38Z</dc:date>
    </item>
  </channel>
</rss>

