<?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: Different criteria for each group using loops in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Different-criteria-for-each-group-using-loops/m-p/804528#M316839</link>
    <description>&lt;P&gt;It might help to describe how you intend to use this.&lt;/P&gt;
&lt;P&gt;It could be than your additional variables are not even needed and a format would suffice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format;

value test1_
low -&amp;lt;65 = '0'
65-high = '1'
;
value test2_
low -&amp;lt;70 = '0'
70-high = '1'
;

data example;
  input test1 test2;
datalines;
45   50
64.9 69.9
65   70
99   81
;

proc print data=example;
   format test1 test1_. test2 test2_.;
run;
&lt;/PRE&gt;
&lt;P&gt;The formatted values would be used by report, most analysis and graphing procedures.&lt;/P&gt;
&lt;P&gt;If your request for a "loop" was because you have a large number of "test" values to recode the format may be more efficient if some (or many or most) of the test values have identical ranges. Just assign the same format to multiple variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Plus if at a later date it is determined that the cutoff for test2 should be 69.5 instead of 70 you only need to change the code in the format. There would be no need to rebuild the data set again just run the report, analysis or graphs using the new format definition assigned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a restriction on format names that they not end in a number hence the _ in the names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 28 Mar 2022 15:06:18 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-03-28T15:06:18Z</dc:date>
    <item>
      <title>Different criteria for each group using loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Different-criteria-for-each-group-using-loops/m-p/804430#M316781</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following code that i would like to turn into a loop.:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data testset;
set test;
if Test1 &amp;gt;= 65 
	then Passed1=1;
	else Passed1=0;
if Test2 &amp;gt;= 70 
	then Passed2=1;
	else Passed2=0;
if Test3 &amp;gt;= 60
	then Passed3=1;
	else Passed3=0;
if Test4 &amp;gt;= 62
	then Passed4=1;
	else Passed4=0;
if Test5 &amp;gt;= 68
	then Passed5=1;
	else Passed5=0;
output;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So far, i was able to come up with :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data testset (drop=i);
set test;
ARRAY Test{5} Test1-Test5;
ARRAY Passed{5};
DO i=1 TO 5;
IF Test{1} &amp;gt;= 65 OR Test{2} &amp;gt;= 70 OR Test{3} &amp;gt;= 60 OR Test{4} &amp;gt;= 62 OR Test{5} &amp;gt;= 68
THEN Passed{i}=1;
ELSE Passed{i}=0;
END;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What I want it todo is to put the respective 'passed' as 1 if it meets the criteria and 0 if it doesn't. Each group has a different criteria to be met but the code i wrote doesnt do that. I know its because i used "OR" but what would I use to fix it so that it gives me the output i want for each individual group?&lt;/P&gt;</description>
      <pubDate>Sun, 27 Mar 2022 19:22:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Different-criteria-for-each-group-using-loops/m-p/804430#M316781</guid>
      <dc:creator>SASUsr007</dc:creator>
      <dc:date>2022-03-27T19:22:21Z</dc:date>
    </item>
    <item>
      <title>Re: Different criteria for each group using loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Different-criteria-for-each-group-using-loops/m-p/804436#M316785</link>
      <description>&lt;P&gt;To turn this into a loop you would need a third array holding the cutoffs.&amp;nbsp; I'm not sure this is any clearer than&amp;nbsp; your original program, but here is the idea:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data testset (drop=i);
set test;
ARRAY Test{5} Test1-Test5;
ARRAY Passed{5};
array cutoffs {5} _temporary_ (65 70 60 62 68);
do i=1 to 5;
  if test{i} &amp;gt;= cutoffs{i} then Passed{i}=1;
   else Passed{i}=0;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 27 Mar 2022 20:13:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Different-criteria-for-each-group-using-loops/m-p/804436#M316785</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-03-27T20:13:53Z</dc:date>
    </item>
    <item>
      <title>Re: Different criteria for each group using loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Different-criteria-for-each-group-using-loops/m-p/804438#M316787</link>
      <description>That is perfect! Thank you so much.</description>
      <pubDate>Sun, 27 Mar 2022 20:57:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Different-criteria-for-each-group-using-loops/m-p/804438#M316787</guid>
      <dc:creator>SASUsr007</dc:creator>
      <dc:date>2022-03-27T20:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: Different criteria for each group using loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Different-criteria-for-each-group-using-loops/m-p/804528#M316839</link>
      <description>&lt;P&gt;It might help to describe how you intend to use this.&lt;/P&gt;
&lt;P&gt;It could be than your additional variables are not even needed and a format would suffice.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format;

value test1_
low -&amp;lt;65 = '0'
65-high = '1'
;
value test2_
low -&amp;lt;70 = '0'
70-high = '1'
;

data example;
  input test1 test2;
datalines;
45   50
64.9 69.9
65   70
99   81
;

proc print data=example;
   format test1 test1_. test2 test2_.;
run;
&lt;/PRE&gt;
&lt;P&gt;The formatted values would be used by report, most analysis and graphing procedures.&lt;/P&gt;
&lt;P&gt;If your request for a "loop" was because you have a large number of "test" values to recode the format may be more efficient if some (or many or most) of the test values have identical ranges. Just assign the same format to multiple variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Plus if at a later date it is determined that the cutoff for test2 should be 69.5 instead of 70 you only need to change the code in the format. There would be no need to rebuild the data set again just run the report, analysis or graphs using the new format definition assigned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is a restriction on format names that they not end in a number hence the _ in the names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Mar 2022 15:06:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Different-criteria-for-each-group-using-loops/m-p/804528#M316839</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-28T15:06:18Z</dc:date>
    </item>
  </channel>
</rss>

