BookmarkSubscribeRSS Feed
Nasya
Obsidian | Level 7

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
 
2 REPLIES 2
Astounding
PROC Star

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;

Reeza
Super User

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 654 views
  • 2 likes
  • 3 in conversation