<?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 Coding to select rows that fulfill two or more variable conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Coding-to-select-rows-that-fulfill-two-or-more-variable/m-p/832359#M328983</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have four variables that are coded as 0/1, and want to write if-then statements to produce a new variable if two or more of the variables =1. I could write out every feasible combination of the variables, but I'm certain there must be a more efficient and elegant way than:&lt;/P&gt;&lt;P&gt;if (var1=1 and var2=1 and var3=0 and var4=0) or (var1=1 and var2=0 and var3=1 and var4=0) or...... and so on&lt;/P&gt;&lt;P&gt;then newvar=1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I'm a fairly new with SAS and not sure how to approach differently. Any insight would be appreciated. Thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 08 Sep 2022 17:06:39 GMT</pubDate>
    <dc:creator>epialy</dc:creator>
    <dc:date>2022-09-08T17:06:39Z</dc:date>
    <item>
      <title>Coding to select rows that fulfill two or more variable conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Coding-to-select-rows-that-fulfill-two-or-more-variable/m-p/832359#M328983</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have four variables that are coded as 0/1, and want to write if-then statements to produce a new variable if two or more of the variables =1. I could write out every feasible combination of the variables, but I'm certain there must be a more efficient and elegant way than:&lt;/P&gt;&lt;P&gt;if (var1=1 and var2=1 and var3=0 and var4=0) or (var1=1 and var2=0 and var3=1 and var4=0) or...... and so on&lt;/P&gt;&lt;P&gt;then newvar=1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I'm a fairly new with SAS and not sure how to approach differently. Any insight would be appreciated. Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2022 17:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Coding-to-select-rows-that-fulfill-two-or-more-variable/m-p/832359#M328983</guid>
      <dc:creator>epialy</dc:creator>
      <dc:date>2022-09-08T17:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: Coding to select rows that fulfill two or more variable conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Coding-to-select-rows-that-fulfill-two-or-more-variable/m-p/832362#M328986</link>
      <description>&lt;P&gt;How about a simple sum&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
	/* set up test data */
	do var1=0 to 1 ;
		do var2=0 to 1 ;
			do var3=0 to 1 ;
				do var4=0 to 1 ;
					/* code to set newvar if 2 or more var1-4 are set to 1 */
					x=sum(var1,var2,var3,var4) ;
					if x&amp;gt;1 then
						newvar=1 ;
					else 
						newvar=0 ;
					/* output all variables to dataset */ 
					output ;
					/* end  do loops for test data */
				end ;
			end ;
		end ;
	end ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Sep 2022 17:28:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Coding-to-select-rows-that-fulfill-two-or-more-variable/m-p/832362#M328986</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2022-09-08T17:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: Coding to select rows that fulfill two or more variable conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Coding-to-select-rows-that-fulfill-two-or-more-variable/m-p/832363#M328987</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NewVar = sum(of var1-var4) &amp;gt; 1;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Condensing&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/226241"&gt;@AMSAS&lt;/a&gt;&amp;nbsp;solution somewhat you can use the above as an example. Exactly how you list the variables in the SUM() can vary a few ways, from explicitly listing them to shortcut lists.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a reference that illustrates how to refer to variables and datasets in a short cut list:&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2022 17:30:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Coding-to-select-rows-that-fulfill-two-or-more-variable/m-p/832363#M328987</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-09-08T17:30:36Z</dc:date>
    </item>
  </channel>
</rss>

