<?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: IF-THEN statement not performing math equations when condition is met. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-statement-not-performing-math-equations-when-condition/m-p/862212#M340558</link>
    <description>&lt;P&gt;Computers cannot represent fractions (that are not integer powers of 2) exactly. So, if you want to find something that equals a fractional value, you may have to round.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if round(visitnum-visitnum1,0.01) = round(0.19,0.01) then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or use the FUZZ function&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if fuzz(visitnum-visitnum1-0.19)=0 then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Mar 2023 21:53:38 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-03-03T21:53:38Z</dc:date>
    <item>
      <title>IF-THEN statement not performing math equations when condition is met.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-statement-not-performing-math-equations-when-condition/m-p/862209#M340557</link>
      <description>&lt;P&gt;I want unscheduled visits indicated by *.19 and *.2 to be marked as such in AVISITN and AVIST. For example, I want ID = 1, VISITNUM = 104 to result in AVISITN = 202.19, AVISIT = "3 Days Post Dose 2 (S)". However, both AVISITN and AVISIT are coming up as blank for those visits.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 input ID VISIT $ VISITNUM @@;
 cards;
 1 DAY1 101
 1 DAY2 102
 1 DAY3 103
 1 DAY4 104.19
 1 DAY5 105
 2 DAY1 101
 2 DAY2 102.2
 2 DAY3 103
 3 DAY1 101
 3 DAY2 102
 3 DAY3 103.19
 3 DAY4 104
 3 DAY5 105
 ;
run;

data have2;
 set have;
 length avisit1 $30.;
 	visitnum1 = int(visitnum);
	if visitnum1 = 101					then do; avisit1n = 101; avisit1 = 'Dose 1'; 			end;
	if visitnum1 = 102					then do; avisit1n = 102; avisit1 = '3 Days Post Dose 1';end;
	if visitnum1 = 103					then do; avisit1n = 201; avisit1 = 'Dose 2';			end;
	if visitnum1 = 104					then do; avisit1n = 202; avisit1 = '3 Days Post Dose 2';end;
	if visitnum1 = 105					then do; avisit1n = 203; avisit1 = '7 Days Post Dose 2';end;

 	if visitnum ^= visitnum1			then do;
		if visitnum-visitnum1 = 0.19	then do; avisitn = avisit1n + 0.19; avisit = strip(avisit1)||' (S)'; end;
		if visitnum-visitnum1 = 0.20	then do; avisitn = avisit1n + 0.20; avisit = strip(avisit1)||' (T)'; end;
	end;
		else								 do; avisitn = avisit1n; avisit = avisit1; 						 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;EM&gt;Aside:&lt;/EM&gt; I attempted to make WANT dataset, but it kept reading each spacing as a new variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 input ID AVISIT $ AVISITN @@;
 length AVIST $18.;
 cards;
 1 
 Dose 1            
 101
 1 
 3 Days Post Dose 1
 102
 1 
 Dose 2
 201
 1
 3 Days Post Dose 2 (S)
 201.19
 1 
 7 Days Post Dose 2
 203
 2 
 Dose 1 
 101
 2 
 3 Days Post Dose 1 (T)
 102.2
 2 
 Dose 2
 201
 3 Dose 1 101
 3 
 3 Days Post Dose 1 
 102
 3 
 Dose 2 (S)
 201.19
 3 
 3 Days Post Dose 2 
 202
 3 
 7 Days Post Dose 2 
 203
 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Mar 2023 20:37:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-statement-not-performing-math-equations-when-condition/m-p/862209#M340557</guid>
      <dc:creator>mariko5797</dc:creator>
      <dc:date>2023-03-03T20:37:15Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN statement not performing math equations when condition is met.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-statement-not-performing-math-equations-when-condition/m-p/862212#M340558</link>
      <description>&lt;P&gt;Computers cannot represent fractions (that are not integer powers of 2) exactly. So, if you want to find something that equals a fractional value, you may have to round.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if round(visitnum-visitnum1,0.01) = round(0.19,0.01) then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or use the FUZZ function&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if fuzz(visitnum-visitnum1-0.19)=0 then do;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2023 21:53:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-statement-not-performing-math-equations-when-condition/m-p/862212#M340558</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-03T21:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: IF-THEN statement not performing math equations when condition is met.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-THEN-statement-not-performing-math-equations-when-condition/m-p/862218#M340559</link>
      <description>&lt;P&gt;You could try the resolve() function to evaluate that expression in the section of the DATA step that seems to be causing the issue. Like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;if resolve(visitnum-visitnum1) = 0.19	then do; avisitn = avisit1n + 0.19; avisit = strip(avisit1)||' (S)'; end;
if resolve(visitnum-visitnum1) = 0.20	then do; avisitn = avisit1n + 0.20; avisit = strip(avisit1)||' (T)'; end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Mar 2023 21:12:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-THEN-statement-not-performing-math-equations-when-condition/m-p/862218#M340559</guid>
      <dc:creator>svh</dc:creator>
      <dc:date>2023-03-03T21:12:57Z</dc:date>
    </item>
  </channel>
</rss>

