DATA Step, Macro, Functions and more

Handling multiple variables using IF condition

Reply
Contributor
Posts: 25

Handling multiple variables using IF condition

Hi,

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.

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;
This error is popping up. Any help is appreciated.
! (AEACNSP=o_AEACNSP, (AEOUT=o_AEOUT, (LPSDAT_=o_LPSDAT_ )))))))))))))) then do;
ERROR 22-322: Syntax error, expecting one of the following: (, [, {.
 
ERROR 76-322: Syntax error, statement will be ignored.
 
Thank you,
 
Regards,
Nasya
 
Super User
Posts: 6,785

Re: Handling multiple variables using IF condition

[ Edited ]

SAS has its own rules for coding multiple conditions.  You'll need to learn them ... just no way to get around it.  Here's one possible way to code some of your logic.  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:

 

if (AETERM = o_AETERM) and (AESEV=o_AESEV) and (AESER=o_AESER)

   and (YESREAS=o_YESREAS) and (AEREAD=o_AEREAD) and

   (AEINTROP=o_AEINTROP) and (AEREL=o_AEREL) and (AEANT= o_AEANT)  

   and (AESTDAT_=o_AESTDAT_) and (AEENDAT_=o_AEENDAT_) and

   (AEACN=o_AEACN) and (AEACNSP=o_AEACNSP) and (AEOUT=o_AEOUT)

   and (LPSDAT_=o_LPSDAT_) then do;
       Status='No Change';

end;

Super User
Posts: 23,771

Re: Handling multiple variables using IF condition

Posted in reply to Astounding

You could simplify this possibly by putting the variable lists into arrays and seeing if they elements are equal. 

Ask a Question
Discussion stats
  • 2 replies
  • 71 views
  • 2 likes
  • 3 in conversation