<?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 Handling multiple variables using IF condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Handling-multiple-variables-using-IF-condition/m-p/474996#M122123</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying the following code and can some one let me know where this is going wrong? I am trying to compare all the terms from AE and with the ' if ' condition display the output as NEW/NO CHANGE/UPDATED.&lt;/P&gt;&lt;PRE&gt;data final;
	merge  der1_ (in=a) der4_ (in=b) ied (in=c) dmr (in=d) rfr(in=e);
	by UNOSID;

	if b;

 keep SUBJECT AETERM AESEV AESER YESREAS AEREAD AEINTROP AEREL AEANT AESTDAT_ AEENDAT_ AEACN AEACNSP AEOUT LPSDAT_ PULREL AEYES AECM TDDAT_ TDDAYS SEX_D DTHDAT_ AGE_D DTHCAU DTHCAUSP ARREST HOSPDDAT_ DDIS RRINDIC RRINDOT RRCINDIC RFHEPC RFCANCER SEX AGE MELD INC4 EAD;
run;

proc sort data=final NODUPKEY;
	by _ALL_;
RUN;

proc sort data=final  out=c_final ;
  by SUBJECT;
run;

proc sort data=previous.final  out=o_final(rename=(AETERM =o_AETERM AESEV=o_AESEV AESER=o_AESER YESREAS=o_YESREAS AEREAD=o_AEREAD 
										           AEINTROP=o_AEINTROP AEREL=o_AEREL AEANT= o_AEANT AESTDAT_=o_AESTDAT_ AEENDAT_=o_AEENDAT_
										           AEACN=o_AEACN AEACNSP=o_AEACNSP AEOUT=o_AEOUT LPSDAT_=o_LPSDAT_));
  by SUBJECT;
run;

/* Create a new dataset with the new variable STATUS.
   STATUS is reflected in the output as NO CHANGE, UPDATED accordingly*/

data current.final;
  attrib STATUS length=$25.;
  	merge c_final(in=a) o_final(in=b keep=SUBJECT o_AETERM o_AESEV o_AESER o_YESREAS o_AEREAD o_AEINTROP o_AEREL o_AEANT o_AESTDAT_ o_AEENDAT_ o_AEACN o_AEACNSP o_AEOUT o_LPSDAT_);
  by SUBJECT;

 	if a and b then do;
      if ((AETERM = o_AETERM , (AESEV=o_AESEV , (AESER=o_AESER , (YESREAS=o_YESREAS , (AEREAD=o_AEREAD, (AEINTROP=o_AEINTROP, (AEREL=o_AEREL, (AEANT= o_AEANT, (AESTDAT_=o_AESTDAT_, (AEENDAT_=o_AEENDAT_, (AEACN=o_AEACN, (AEACNSP=o_AEACNSP, (AEOUT=o_AEOUT, (LPSDAT_=o_LPSDAT_ ))))))))))))))) then do;
   		Status='No Change';
  end;
	
   if (AETERM ne o_AETERM, (AESEV ne o_AESEV, (AESER ne o_AESER, (YESREAS ne o_YESREAS, (AEREAD ne o_AEREAD, (AEINTROP ne o_AEINTROP, (AEREL ne o_AEREL, (AEANT ne o_AEANT, (AESTDAT_ ne o_AESTDAT_, (AEENDAT_ ne o_AEENDAT_, (AEACN ne o_AEACN, (AEACNSP ne o_AEACNSP, (AEOUT ne o_AEOUT, (LPSDAT_ ne o_LPSDAT_)))))))))))))) then do;
   if a ne b then do;
        Status='Updated';
    end;
    
   if a and not b then do;
    Status='New';
    output;
  end;
 
run;&lt;/PRE&gt;&lt;DIV class="sasSource"&gt;This error is popping up. Any help is appreciated.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;! (AEACNSP=o_AEACNSP, (AEOUT=o_AEOUT, (LPSDAT_=o_LPSDAT_ )))))))))))))) then do;&lt;/DIV&gt;&lt;DIV class="sasError focus-line"&gt;ERROR 22-322: Syntax error, expecting one of the following: (, [, {.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;Thank you,&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;Regards,&lt;/DIV&gt;&lt;DIV class="sasError"&gt;Nasya&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
    <pubDate>Mon, 02 Jul 2018 17:47:58 GMT</pubDate>
    <dc:creator>Nasya</dc:creator>
    <dc:date>2018-07-02T17:47:58Z</dc:date>
    <item>
      <title>Handling multiple variables using IF condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-multiple-variables-using-IF-condition/m-p/474996#M122123</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying the following code and can some one let me know where this is going wrong? I am trying to compare all the terms from AE and with the ' if ' condition display the output as NEW/NO CHANGE/UPDATED.&lt;/P&gt;&lt;PRE&gt;data final;
	merge  der1_ (in=a) der4_ (in=b) ied (in=c) dmr (in=d) rfr(in=e);
	by UNOSID;

	if b;

 keep SUBJECT AETERM AESEV AESER YESREAS AEREAD AEINTROP AEREL AEANT AESTDAT_ AEENDAT_ AEACN AEACNSP AEOUT LPSDAT_ PULREL AEYES AECM TDDAT_ TDDAYS SEX_D DTHDAT_ AGE_D DTHCAU DTHCAUSP ARREST HOSPDDAT_ DDIS RRINDIC RRINDOT RRCINDIC RFHEPC RFCANCER SEX AGE MELD INC4 EAD;
run;

proc sort data=final NODUPKEY;
	by _ALL_;
RUN;

proc sort data=final  out=c_final ;
  by SUBJECT;
run;

proc sort data=previous.final  out=o_final(rename=(AETERM =o_AETERM AESEV=o_AESEV AESER=o_AESER YESREAS=o_YESREAS AEREAD=o_AEREAD 
										           AEINTROP=o_AEINTROP AEREL=o_AEREL AEANT= o_AEANT AESTDAT_=o_AESTDAT_ AEENDAT_=o_AEENDAT_
										           AEACN=o_AEACN AEACNSP=o_AEACNSP AEOUT=o_AEOUT LPSDAT_=o_LPSDAT_));
  by SUBJECT;
run;

/* Create a new dataset with the new variable STATUS.
   STATUS is reflected in the output as NO CHANGE, UPDATED accordingly*/

data current.final;
  attrib STATUS length=$25.;
  	merge c_final(in=a) o_final(in=b keep=SUBJECT o_AETERM o_AESEV o_AESER o_YESREAS o_AEREAD o_AEINTROP o_AEREL o_AEANT o_AESTDAT_ o_AEENDAT_ o_AEACN o_AEACNSP o_AEOUT o_LPSDAT_);
  by SUBJECT;

 	if a and b then do;
      if ((AETERM = o_AETERM , (AESEV=o_AESEV , (AESER=o_AESER , (YESREAS=o_YESREAS , (AEREAD=o_AEREAD, (AEINTROP=o_AEINTROP, (AEREL=o_AEREL, (AEANT= o_AEANT, (AESTDAT_=o_AESTDAT_, (AEENDAT_=o_AEENDAT_, (AEACN=o_AEACN, (AEACNSP=o_AEACNSP, (AEOUT=o_AEOUT, (LPSDAT_=o_LPSDAT_ ))))))))))))))) then do;
   		Status='No Change';
  end;
	
   if (AETERM ne o_AETERM, (AESEV ne o_AESEV, (AESER ne o_AESER, (YESREAS ne o_YESREAS, (AEREAD ne o_AEREAD, (AEINTROP ne o_AEINTROP, (AEREL ne o_AEREL, (AEANT ne o_AEANT, (AESTDAT_ ne o_AESTDAT_, (AEENDAT_ ne o_AEENDAT_, (AEACN ne o_AEACN, (AEACNSP ne o_AEACNSP, (AEOUT ne o_AEOUT, (LPSDAT_ ne o_LPSDAT_)))))))))))))) then do;
   if a ne b then do;
        Status='Updated';
    end;
    
   if a and not b then do;
    Status='New';
    output;
  end;
 
run;&lt;/PRE&gt;&lt;DIV class="sasSource"&gt;This error is popping up. Any help is appreciated.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;! (AEACNSP=o_AEACNSP, (AEOUT=o_AEOUT, (LPSDAT_=o_LPSDAT_ )))))))))))))) then do;&lt;/DIV&gt;&lt;DIV class="sasError focus-line"&gt;ERROR 22-322: Syntax error, expecting one of the following: (, [, {.&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;ERROR 76-322: Syntax error, statement will be ignored.&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;Thank you,&lt;/DIV&gt;&lt;DIV class="sasError"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasError"&gt;Regards,&lt;/DIV&gt;&lt;DIV class="sasError"&gt;Nasya&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Mon, 02 Jul 2018 17:47:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-multiple-variables-using-IF-condition/m-p/474996#M122123</guid>
      <dc:creator>Nasya</dc:creator>
      <dc:date>2018-07-02T17:47:58Z</dc:date>
    </item>
    <item>
      <title>Re: Handling multiple variables using IF condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-multiple-variables-using-IF-condition/m-p/475004#M122128</link>
      <description>&lt;P&gt;SAS has its own rules for coding multiple conditions.&amp;nbsp; You'll need to learn them ... just no way to get around it.&amp;nbsp; Here's one possible way to code some of your logic.&amp;nbsp; I can't guarantee that it gives the right answer (your intention isn't clear since it's not valid SAS code) but it shows the type of code that SAS is expecting:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;if (AETERM = o_AETERM) and (AESEV=o_AESEV) and (AESER=o_AESER) &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; and&amp;nbsp;(YESREAS=o_YESREAS) and&lt;FONT face="courier new,courier"&gt;&amp;nbsp;(AEREAD=o_AEREAD) and &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; (AEINTROP=o_AEINTROP) and (AEREL=o_AEREL) and (AEANT= o_AEANT)&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; and&amp;nbsp;(AESTDAT_=o_AESTDAT_) and (AEENDAT_=o_AEENDAT_) and &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; (AEACN=o_AEACN) and (AEACNSP=o_AEACNSP)&amp;nbsp;&lt;FONT face="courier new,courier"&gt;and&lt;FONT face="courier new,courier"&gt; (AEOUT=o_AEOUT) &lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp; and (LPSDAT_=o_LPSDAT_) then do;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Status='No Change';&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;FONT face="courier new,courier"&gt;end;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jul 2018 18:11:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-multiple-variables-using-IF-condition/m-p/475004#M122128</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-02T18:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: Handling multiple variables using IF condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Handling-multiple-variables-using-IF-condition/m-p/475039#M122138</link>
      <description>&lt;P&gt;You could simplify this possibly by putting the variable lists into arrays and seeing if they elements are equal.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Jul 2018 20:06:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Handling-multiple-variables-using-IF-condition/m-p/475039#M122138</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-02T20:06:01Z</dc:date>
    </item>
  </channel>
</rss>

