<?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: Using one IF-ELSE condition for multiple variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-one-IF-ELSE-condition-for-multiple-variables/m-p/810819#M319762</link>
    <description>&lt;P&gt;The then do did the trick, I have the 3 variables as macro variables so the option of increments was not viable, but will keep it in the back pocket. Thank you&lt;/P&gt;</description>
    <pubDate>Sat, 30 Apr 2022 15:22:14 GMT</pubDate>
    <dc:creator>Mruizv</dc:creator>
    <dc:date>2022-04-30T15:22:14Z</dc:date>
    <item>
      <title>Using one IF-ELSE condition for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-one-IF-ELSE-condition-for-multiple-variables/m-p/810813#M319760</link>
      <description>&lt;P&gt;Hello, trying to figure out if there is a way to apply same If-Else condition to 2 variables at the same time&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Current code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA random1;
	set agree;
	random=ranuni(456);
RUN;
 
 
DATA random1;
	set random1;
		if random LT &amp;amp;cutoff1 then rater1='Yes';
				else rater2='Yes';
		 if random GE &amp;amp;cutoff1 and random LT &amp;amp;cutoff2 then rater1='Yes';
				else rater2='No';
		if random GE &amp;amp;cutoff2 and random LT &amp;amp;cutoff3 then rater1='No';
				else rater2='Yes';
		 if random GE &amp;amp;cutoff3  then rater1='No';
				else rater2='No';
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I am getting No for rater2 at values less than 0.4 when it should be Yes and yes for rater2 at larger than 0.6 when it should be No&lt;/P&gt;
&lt;P&gt;Cutoff1= 0.4 cutoff2=0.5 and cutoff3=0.6 currently&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Mruizv_1-1651324803730.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71024iBA257710007B888A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Mruizv_1-1651324803730.png" alt="Mruizv_1-1651324803730.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 30 Apr 2022 13:21:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-one-IF-ELSE-condition-for-multiple-variables/m-p/810813#M319760</guid>
      <dc:creator>Mruizv</dc:creator>
      <dc:date>2022-04-30T13:21:01Z</dc:date>
    </item>
    <item>
      <title>Re: Using one IF-ELSE condition for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-one-IF-ELSE-condition-for-multiple-variables/m-p/810818#M319761</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/402297"&gt;@Mruizv&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you want to randomly assign the four possible combinations of 'Yes' and 'No' to variables RATER1 and RATER2 with certain probabilities: ('Yes', 'Yes') and ('No', 'No') each with probability 0.4 and each of the other two combinations with probability 0.1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way to achieve this similarly to what you've tried is to use DO-END blocks containing the assignment statements for RATER1 and RATER2:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data random1;
set agree;
random=ranuni(456);
if random &amp;lt; &amp;amp;cutoff1 then do;
  rater1='Yes';
  rater2='Yes';
end;
else if random &amp;lt; &amp;amp;cutoff2 then do;
  rater1='Yes';
  rater2='No';
end;
else if random &amp;lt; &amp;amp;cutoff3 then do;
  rater1='No';
  rater2='Yes';
end;
else do;
  rater1='No';
  rater2='No';
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(Note that this would replace your two DATA steps.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you could simplify the code as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data random1;
set agree;
random=ranuni(456);
if random &amp;lt; &amp;amp;cutoff2 then rater1='Yes';
else rater1='No';
if random &amp;lt; &amp;amp;cutoff1 | &amp;amp;cutoff2 &amp;lt;= random &amp;lt; &amp;amp;cutoff3 then rater2='Yes';
else rater2='No';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, you could use a better random number generator plus the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p0fpeei0opypg8n1b06qe4r040lv.htm#p0rssof65ddoyyn1s3kfdap849lr" target="_blank" rel="noopener"&gt;RAND function&lt;/A&gt;&amp;nbsp;(with the "tabled distribution") creating random numbers 1, 2, 3, 4 with probabilities 0.4, 0.1, 0.1, 0.4:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data random1;
call streaminit(456);
set agree;
random=rand('table',0.4, 0.1, 0.1);
if random &amp;lt;= 2 then rater1='Yes';
else rater1='No';
if mod(random,2) then rater2='Yes';
else rater2='No';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Often it's more convenient to use numeric variables with values 1 and 0 instead of character variables with values 'Yes' and 'No':&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data random1;
call streaminit(456);
set agree;
random=rand('table',0.4, 0.1, 0.1);
rater1=(random &amp;lt;= 2);
rater2=mod(random,2);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 30 Apr 2022 15:11:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-one-IF-ELSE-condition-for-multiple-variables/m-p/810818#M319761</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-04-30T15:11:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using one IF-ELSE condition for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-one-IF-ELSE-condition-for-multiple-variables/m-p/810819#M319762</link>
      <description>&lt;P&gt;The then do did the trick, I have the 3 variables as macro variables so the option of increments was not viable, but will keep it in the back pocket. Thank you&lt;/P&gt;</description>
      <pubDate>Sat, 30 Apr 2022 15:22:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-one-IF-ELSE-condition-for-multiple-variables/m-p/810819#M319762</guid>
      <dc:creator>Mruizv</dc:creator>
      <dc:date>2022-04-30T15:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: Using one IF-ELSE condition for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-one-IF-ELSE-condition-for-multiple-variables/m-p/810821#M319764</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/402297"&gt;@Mruizv&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have the 3 variables as macro variables so the option of increments was not viable, ...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You could use your macro variables instead of the hardcoded probabilities:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;random=rand('table', &amp;amp;cutoff1, &amp;amp;cutoff2-&amp;amp;cutoff1, &amp;amp;cutoff3-&amp;amp;cutoff2);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 30 Apr 2022 15:47:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-one-IF-ELSE-condition-for-multiple-variables/m-p/810821#M319764</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-04-30T15:47:22Z</dc:date>
    </item>
  </channel>
</rss>

