<?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: Identifying if a set of variables meets a condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Identifying-if-a-set-of-variables-meets-a-condition/m-p/681717#M206239</link>
    <description>&lt;P&gt;Use LARGEST() &lt;BR /&gt;&lt;BR /&gt;Your logic can be generalized to check that the largest value is greater than 0.6 and the second largest value must be less than 0.4 for the rest to be less than 0.4. No macros. Use the colon to automatically refer to all variables that start with score so its dynamic as well. If you have other variables that start with the prefix score this will not work. For other options in that case, see the short cut list link below.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if largest(1, of score:) &amp;gt; =0.6 and largest(2, of score:) &amp;lt;= 0.4 then condition=1; 
else condition = 0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Largest function&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n1hqpyj2pz85u2n1fcl1uoh5rx2l.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n1hqpyj2pz85u2n1fcl1uoh5rx2l.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/46908"&gt;@RyanSimmons&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am a bit stuck on how to automate this programming issue. I am trying to write a macro to perform this but can't seem to figure out a clean way of doing it so it is generalizable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The input to this macro is going to be a numeric dataset with ~30-50 observations and anywhere from 2 to 10 variables. This dataset will be structure like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA input;
	do Item = 1 to 30;
		Score1 = rand('uniform');
		Score2 = rand('uniform');
		Score3 = rand('uniform');
		output;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But the exact numbers will vary for each such input dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I need to do is evaluate for each Item (i.e. row) whether or not the set of Scores (columns) meets a condition. The condition is:&amp;nbsp;&lt;EM&gt;exactly one&lt;/EM&gt; of the Scores is &amp;gt;= 0.6&amp;nbsp;&lt;EM&gt;and&lt;/EM&gt; each other score is &amp;lt;=0.4. Now, for the example dataset, this can be coded pretty easily using something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA output;
	set input;
	if Score1 &amp;gt;= 0.6 &amp;amp; Score2 &amp;lt;= 0.4 &amp;amp; Score3 &amp;lt;= 0.4 then condition = 1;
	else if Score1 &amp;lt;= 0.4 &amp;amp; Score2 &amp;gt;=0.6 &amp;amp; Score3 &amp;lt;= 0.4 then condition = 1;
	else if Score1 &amp;lt;= 0.4 &amp;amp; Score2 &amp;lt;= 0.4 &amp;amp; Score3 &amp;gt;=0.6 then condition = 1;
	else condition = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;The problem of course is that this isn't easily generalizable, this only works if there are exactly 3 variables.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;How would I automate/generalize this logic in a macro? I'm pretty stuck, I don't really know what to do. I'm guessing there is a way to do this with arrays but I can't quite figure out how to implement that.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 04 Sep 2020 18:09:39 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2020-09-04T18:09:39Z</dc:date>
    <item>
      <title>Identifying if a set of variables meets a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-if-a-set-of-variables-meets-a-condition/m-p/681712#M206236</link>
      <description>&lt;P&gt;I am a bit stuck on how to automate this programming issue. I am trying to write a macro to perform this but can't seem to figure out a clean way of doing it so it is generalizable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The input to this macro is going to be a numeric dataset with ~30-50 observations and anywhere from 2 to 10 variables. This dataset will be structure like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA input;
	do Item = 1 to 30;
		Score1 = rand('uniform');
		Score2 = rand('uniform');
		Score3 = rand('uniform');
		output;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But the exact numbers will vary for each such input dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I need to do is evaluate for each Item (i.e. row) whether or not the set of Scores (columns) meets a condition. The condition is:&amp;nbsp;&lt;EM&gt;exactly one&lt;/EM&gt; of the Scores is &amp;gt;= 0.6&amp;nbsp;&lt;EM&gt;and&lt;/EM&gt; each other score is &amp;lt;=0.4. Now, for the example dataset, this can be coded pretty easily using something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA output;
	set input;
	if Score1 &amp;gt;= 0.6 &amp;amp; Score2 &amp;lt;= 0.4 &amp;amp; Score3 &amp;lt;= 0.4 then condition = 1;
	else if Score1 &amp;lt;= 0.4 &amp;amp; Score2 &amp;gt;=0.6 &amp;amp; Score3 &amp;lt;= 0.4 then condition = 1;
	else if Score1 &amp;lt;= 0.4 &amp;amp; Score2 &amp;lt;= 0.4 &amp;amp; Score3 &amp;gt;=0.6 then condition = 1;
	else condition = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The problem of course is that this isn't easily generalizable, this only works if there are exactly 3 variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How would I automate/generalize this logic in a macro? I'm pretty stuck, I don't really know what to do. I'm guessing there is a way to do this with arrays but I can't quite figure out how to implement that.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Sep 2020 18:00:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-if-a-set-of-variables-meets-a-condition/m-p/681712#M206236</guid>
      <dc:creator>RyanSimmons</dc:creator>
      <dc:date>2020-09-04T18:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying if a set of variables meets a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-if-a-set-of-variables-meets-a-condition/m-p/681717#M206239</link>
      <description>&lt;P&gt;Use LARGEST() &lt;BR /&gt;&lt;BR /&gt;Your logic can be generalized to check that the largest value is greater than 0.6 and the second largest value must be less than 0.4 for the rest to be less than 0.4. No macros. Use the colon to automatically refer to all variables that start with score so its dynamic as well. If you have other variables that start with the prefix score this will not work. For other options in that case, see the short cut list link below.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if largest(1, of score:) &amp;gt; =0.6 and largest(2, of score:) &amp;lt;= 0.4 then condition=1; 
else condition = 0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Largest function&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n1hqpyj2pz85u2n1fcl1uoh5rx2l.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n1hqpyj2pz85u2n1fcl1uoh5rx2l.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/46908"&gt;@RyanSimmons&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am a bit stuck on how to automate this programming issue. I am trying to write a macro to perform this but can't seem to figure out a clean way of doing it so it is generalizable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The input to this macro is going to be a numeric dataset with ~30-50 observations and anywhere from 2 to 10 variables. This dataset will be structure like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA input;
	do Item = 1 to 30;
		Score1 = rand('uniform');
		Score2 = rand('uniform');
		Score3 = rand('uniform');
		output;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But the exact numbers will vary for each such input dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I need to do is evaluate for each Item (i.e. row) whether or not the set of Scores (columns) meets a condition. The condition is:&amp;nbsp;&lt;EM&gt;exactly one&lt;/EM&gt; of the Scores is &amp;gt;= 0.6&amp;nbsp;&lt;EM&gt;and&lt;/EM&gt; each other score is &amp;lt;=0.4. Now, for the example dataset, this can be coded pretty easily using something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA output;
	set input;
	if Score1 &amp;gt;= 0.6 &amp;amp; Score2 &amp;lt;= 0.4 &amp;amp; Score3 &amp;lt;= 0.4 then condition = 1;
	else if Score1 &amp;lt;= 0.4 &amp;amp; Score2 &amp;gt;=0.6 &amp;amp; Score3 &amp;lt;= 0.4 then condition = 1;
	else if Score1 &amp;lt;= 0.4 &amp;amp; Score2 &amp;lt;= 0.4 &amp;amp; Score3 &amp;gt;=0.6 then condition = 1;
	else condition = 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;The problem of course is that this isn't easily generalizable, this only works if there are exactly 3 variables.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;How would I automate/generalize this logic in a macro? I'm pretty stuck, I don't really know what to do. I'm guessing there is a way to do this with arrays but I can't quite figure out how to implement that.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Sep 2020 18:09:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-if-a-set-of-variables-meets-a-condition/m-p/681717#M206239</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-09-04T18:09:39Z</dc:date>
    </item>
    <item>
      <title>Re: Identifying if a set of variables meets a condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identifying-if-a-set-of-variables-meets-a-condition/m-p/681730#M206248</link>
      <description>Thanks! I knew the solution would be really simple!</description>
      <pubDate>Fri, 04 Sep 2020 19:05:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identifying-if-a-set-of-variables-meets-a-condition/m-p/681730#M206248</guid>
      <dc:creator>RyanSimmons</dc:creator>
      <dc:date>2020-09-04T19:05:18Z</dc:date>
    </item>
  </channel>
</rss>

