<?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 select the wanted amount of variables? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-the-wanted-amount-of-variables/m-p/233457#M42633</link>
    <description>&lt;P&gt;The idea of creating a new variable is good.&amp;nbsp; However, note that the dash is a minus sign here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;newvar = sum(var1 - var15);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want it to represent a list of variables, you have to add "of" before the list:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;newvar = sum(of var1 - var15);&lt;/P&gt;</description>
    <pubDate>Fri, 06 Nov 2015 15:53:06 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2015-11-06T15:53:06Z</dc:date>
    <item>
      <title>How to select the wanted amount of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-the-wanted-amount-of-variables/m-p/233436#M42622</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have 15 &amp;nbsp;variables, each variable has just two values: 0 and 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to creat another variable (values 0 and 1) which would indicate that from these 15 variables at least 6 have values 1 (or at least 7 and so on)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 14:56:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-the-wanted-amount-of-variables/m-p/233436#M42622</guid>
      <dc:creator>viollete</dc:creator>
      <dc:date>2015-11-06T14:56:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to select the wanted amount of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-the-wanted-amount-of-variables/m-p/233438#M42624</link>
      <description>&lt;P&gt;I don't know what you are&amp;nbsp;going to use this for, but to me it sounds like it&amp;nbsp;would be easier&amp;nbsp;if you transpose your data, then you could just use SQL to sum/count for each id how many '1' you have.&lt;/P&gt;
&lt;P&gt;Another&amp;nbsp;benefit is that you can add more "variables" whenever you want, without changing any logic or change the structure of your data.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 15:04:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-the-wanted-amount-of-variables/m-p/233438#M42624</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2015-11-06T15:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to select the wanted amount of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-the-wanted-amount-of-variables/m-p/233442#M42627</link>
      <description>&lt;P&gt;Easiest is the compare the sum.&lt;/P&gt;
&lt;P&gt;In a data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Newvar = (sum (varname1, varname2 ..., varname15) ge 6);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the variables have nice names like rate1 rate2 ... rate15 then use a variable list&lt;/P&gt;
&lt;P&gt;Newvar = (sum (varname1 - varname15) ge 6);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or possibly you could just use a variable with the total.&lt;/P&gt;
&lt;P&gt;NewVar = sum(varname1 - varname15);&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 15:13:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-the-wanted-amount-of-variables/m-p/233442#M42627</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-11-06T15:13:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to select the wanted amount of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-the-wanted-amount-of-variables/m-p/233457#M42633</link>
      <description>&lt;P&gt;The idea of creating a new variable is good.&amp;nbsp; However, note that the dash is a minus sign here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;newvar = sum(var1 - var15);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want it to represent a list of variables, you have to add "of" before the list:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;newvar = sum(of var1 - var15);&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 15:53:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-the-wanted-amount-of-variables/m-p/233457#M42633</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-11-06T15:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to select the wanted amount of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-the-wanted-amount-of-variables/m-p/233480#M42641</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;The idea of creating a new variable is good.&amp;nbsp; However, note that the dash is a minus sign here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;newvar = sum(var1 - var15);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want it to represent a list of variables, you have to add "of" before the list:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;newvar = sum(of var1 - var15);&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the reminder, generally I'm using that with arrays and didn't want to add complexity for this solution.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 16:43:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-the-wanted-amount-of-variables/m-p/233480#M42641</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-11-06T16:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to select the wanted amount of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-the-wanted-amount-of-variables/m-p/233502#M42643</link>
      <description>&lt;P&gt;If your 15 variables have consecutive internal variable numbers, you could proceed like in the following example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input numberone b c d e f g h i j k l m n nofifteen;
array atleast[15];
do z=1 to 15;
  atleast[z]=(sum(of numberone--nofifteen)&amp;gt;=z);
end;
drop z atleast1-atleast5;
cards;
1 0 0 1 1 0 1 0 0 1 0 1 1 0 1
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This would create variables ATLEAST6, ATLEAST7, ..., ATLEAST15 containing the desired&amp;nbsp;0-1-indicators for "at least 6 ones", "at least 7 ones" and so on.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In order to check if the 15 internal&amp;nbsp;variable numbers are in fact consecutive, run the following step and look where your 15 variables are located in the output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=yourdata varnum;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it turns out that the list of your 15 variables in the above PROC CONTENTS output is interrupted by other variables, modify the order of the variables by running the following step on your dataset (variable names taken from previous example):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data yourdata;
retain numberone b c d e f g h i j k l m n nofifteen;
set yourdata;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will ensure that the list&amp;nbsp;&lt;FONT face="courier new,courier"&gt;numberone--nofifteen&lt;/FONT&gt; contains just the relevant 15 variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Nov 2015 17:50:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-the-wanted-amount-of-variables/m-p/233502#M42643</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-11-06T17:50:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to select the wanted amount of variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-the-wanted-amount-of-variables/m-p/233591#M42668</link>
      <description>&lt;P&gt;Nothing others have suggested already. Just posting a full code sample.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have(drop=_:);
  array var_ {15} 8.;
  do _rows=1 to 20;
    do _i=1 to dim(var_);
      var_{_i}=floor(ranuni(0)*1.5);
    end;
    output;
  end;
run;

data want;
  set have;
  Six_Plus_indicator= ( sum(of var_:) &amp;gt;= 6 );
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 07 Nov 2015 01:46:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-the-wanted-amount-of-variables/m-p/233591#M42668</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2015-11-07T01:46:26Z</dc:date>
    </item>
  </channel>
</rss>

