SAS Macro errors

Reply
Frequent Contributor
Posts: 75

SAS Macro errors

Hi, 

 

I wrote a MACROS but have a lot of errors that I dont understand. I have attached my code and the log, any help is appreciated:

 

%macro incidence ;
	
	%do i = 1 %to 12 ;
	
		%let inf=%scan(int*zoo*othbact*hiv*vir*arth*chly*ricket*spiro*helminth*para*late, &i., *) ;
		
		/*intestinal infectious disease*/
		%let int=%str("001","002","003","004","005","006","007","008","009") ;
		
		/*zoonotic bacterial disease*/
		%let zoo=%str("020","021","022","023","024","025","026","027") ;
		
		/*other bacterial disease*/
		%let othbact=%str("030","031","032","033","034","035","036","037","038","039","040","041");
		
		/*hiv*/
		%let hiv=%str("042") ;
		
		/*viral diseases accompanied by exanthem*/
		%let vir=%str("050","051","052","053","054","055","056","057");
		
		/*arthropod-brone viral disease*/
		%let arth=%str("060","061","062","063","064","065","066");
		
		/*other diseases due to viruses and chlamydiae*/
		%let chly=%str("070","071","072","073","074","075","076","077","078","079");
		
		/*rickettsioses and otehr arthrpod-borne diseases*/
		%let ricket=%str("080","081","082","083","084","085","086","087","088");
		
		/*other spirochetal diseases*/
		%let spiro=%str("100","101","102","103","104");
	
		/*helminthiases*/
		%let helminth=%str("120","121","123","124","125","126","127","128","129");
		
		/*other infectious and parasitic diseases*/
		%let para = %str("130","131","132","133","134","135","136");
		
		/*late effects of infectious and parasitic diseases*/
		%let late=%str("137","138","139");
		
		
	/*FLAG PATIENT WITH THE ABOVE MENTIONED COMORBIDITIES ATFTER INDEX_DATE BUT BEFORE PERIOD_STOP*/;
	data _04_post_ind_&inf. ;
		set derived._01_incidence;
		post_&inf. =1 ;
		where (code in:(&&&inf.)) and (index_date le svcdate le period_stop) ;
	run ;
	
	proc sort data = _04_post_ind_&inf. out= _04_post_index_s_&inf. nodupkey ;
		by enrolid ;
	run ;
	

 

 

      
 
 SYMBOLGEN:  Macro variable INF resolves to int
 MPRINT(INCIDENCE):   data _04_pre_ind_int ;
 MPRINT(INCIDENCE):   set derived._01_incidence;
 SYMBOLGEN:  Macro variable INF resolves to int
 MPRINT(INCIDENCE):   pre_int = 1 ;
 SYMBOLGEN:  && resolves to &.
 SYMBOLGEN:  Macro variable INF resolves to int
 SYMBOLGEN:  Macro variable INT resolves to "001","002","003","004","005","006","007","008","009"
 SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted for printing.
 NOTE: Line generated by the macro variable "INT".
 196         "001","002","003","004","005","006","007","008","009"
             _____ _     _     _
             79    79    79    79
                   200   200   200
 NOTE: Line generated by the macro variable "INT".
 196         "001","002","003","004","005","006","007","008","009"
                                    _
                                    79
 ERROR 79-322: Expecting a (.
 
 ERROR 200-322: The symbol is not recognized and will be ignored.
 
 NOTE: Line generated by the macro variable "INT".
 196         "001","002","003","004","005","006","007","008","009"
                                    _
                                    200
 ERROR 200-322: The symbol is not recognized and will be ignored.
 
 NOTE: Line generated by the macro variable "INT".
 196         "001","002","003","004","005","006","007","008","009"
                                          _
                                          79
 ERROR 79-322: Expecting a (.
 
 NOTE: Line generated by the macro variable "INT".
 196         "001","002","003","004","005","006","007","008","009"
                                          _
                                          200
 ERROR 200-322: The symbol is not recognized and will be ignored.
 
 NOTE: Line generated by the macro variable "INT".
 196         "001","002","003","004","005","006","007","008","009"
                                                _
                                                79
 ERROR 79-322: Expecting a (.
 
 NOTE: Line generated by the macro variable "INT".
 196         "001","002","003","004","005","006","007","008","009"
                                                _
                                                200
 ERROR 200-322: The symbol is not recognized and will be ignored.
 
 NOTE: Line generated by the macro variable "INT".
 196         "001","002","003","004","005","006","007","008","009"
                                                      _
                                                      79
 ERROR 79-322: Expecting a (.
 
 NOTE: Line generated by the macro variable "INT".
 196         "001","002","003","004","005","006","007","008","009"
                                                      _
                                                      200
 ERROR 200-322: The symbol is not recognized and will be ignored.
 


LOG

 79: LINE and COLUMN cannot be determined.
 NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
 ERROR 79-322: Expecting a ).
 MPRINT(INCIDENCE):   where (code in: "001","002","003","004","005","006","007","008","009" ) and (svcdate le index_date) ;
 ERROR: Syntax error while parsing WHERE clause.
 MPRINT(INCIDENCE):   run ;
 
 NOTE: The SAS System stopped processing this step because of errors.
 WARNING: The data set WORK._04_PRE_IND_INT may be incomplete.  When this step was stopped there were 0 observations and 7 variables.
 WARNING: Data set WORK._04_PRE_IND_INT was not replaced because this step was stopped.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds

 

Respected Advisor
Posts: 3,271

Re: SAS Macro errors

[ Edited ]

A couple of comments.

 

Your code is not the same code that the LOG is showing. Perhaps this is a trivial difference and unrelated to the problem you are experiencing, but your code contains variables with "post" in the variable name and data set name, but the LOG shows variables with "pre" in the variable name and data set name. Don't do this. Show us the LOG from the actual code shown.

 

You are doing some very complicated maneuvering using triple-ampersand macro variables to apparently split a big data set into many smaller data sets. This is completely unnecessary, you can keep everything in one large data set, assign the values "int" "zoo" "orthbact" etc. to a variable in the data set, and analyze the results with a BY statement, or if you really only want to analyze part of the data set, then you can use WHERE to get the part you want. So all of this struggling with macros goes away. One large data set is simpler to code and work with. Make your life simple, one big data set is all you need.

 

I believe the specific fix to your code is

 

where (code in:(%unquote(&&&inf.))) and (index_date le svcdate le period_stop) ;

but do yourself a favor, make your life easier, don't use macros here.

--
Paige Miller
Super User
Posts: 6,933

Re: SAS Macro errors

It's an error to use %STR when there are no characters that need to be quoted.  In this case, the WHERE statement is too slow an unquoting and parsing the characters that %STR has quoted.  Just get rid of it.  For example, you have:


  /*intestinal infectious disease*/
%let int=%str("001","002","003","004","005","006","007","008","009") ;

/*zoonotic bacterial disease*/
%let zoo=%str("020","021","022","023","024","025","026","027") ;
 

Instead, use:


  /*intestinal infectious disease*/
%let int="001","002","003","004","005","006","007","008","009";

/*zoonotic bacterial disease*/
%let zoo="020","021","022","023","024","025","026","027";
 

 

There are more than two instances of this ...  you'll need to change all of them.

PROC Star
Posts: 1,471

Re: SAS Macro errors

The code in your log doesn't seem to correspond to the code you posted. 

 

The code has:

data _04_post_ind_&inf. ;

But your log has:

data _04_pre_ind_int ;

I would double-check your code, and that the macro is compiling okay.  It's possible you're just missing parentheses.  They look okay in your code, but I don't see them in your log.  Talking about the parenthesis for the in: operator on the where statement:

where (code in:(&&&inf.)) ...
Super User
Posts: 13,941

Re: SAS Macro errors

Can you please show the code for the entire macro.

Your error message involves code that you do not show in the macro:

The data set: data _04_pre_ind_int has apparently referenced as data _04_pre_ind_&inf has no appearance in the code for the macr that you show. You only show code for data _04_post_ind_ 

 

 

Examine:

MPRINT(INCIDENCE):   where (code in: "001","002","003","004","005","006","007","008","009" ) and (svcdate le index_date) ;
 ERROR: Syntax error while parsing WHERE clause.

notice that there is no ( for the IN operator to use. should have code in ( "001", "002" <etc>

 

which is why you have the error about expecting an ( several lines above the full line of code shown.,

 

In stead of cumbersome macro lists I would likely generate a custom format similar to:

Proc format library=work;
value $CodeGrp
"001","002","003","004","005","006","007","008","009" = 'INT' /*or more descriptive text*/
"020","021","022","023","024","025","026","027"  = 'ZOO'
"030","031","032","033","034","035","036","037","038","039","040","041" = 'OTHBACT'
/* follow the pattern*/
;
run;

/* the list of variables in the P array below should have the suffix
   align with the values of the T array values. The T array values
   are the assigned values of the $codegrp format
*/
data want ;
   set have;
   array p{12} post_int post_zoo post_othbact /*etc*/;
   array t{12} $ 6 _temporary_ ('INT' 'ZOO' 'OTHBACT' /*etc*/);
   where index_date le svcdate le period_stop;
   do i= 1 to dim(p);
      p[i] = ( put(code,$codegrp.) = t[i] );
   end;
run;

Yes this has all of your indicator variables in one data set. The MEAN of the 0/1 coded value is a percentage of the 1 values. SUM would be a count of the 1 values.

 

 

Actually instead of a Pre and Post data set I would actually have two arrays of P values, Pre and post and conditionally assign them based on the values of the date variables.

Super User
Super User
Posts: 8,278

Re: SAS Macro errors

The error message looks like unbalanced ().  Not sure what your mistake is but if you simplify the code a little perhaps you will find it.  Perhaps it is all of unneeded macro quoting that is causing the confusion.

 

Don't put commas into your lists of quoted value.  Then there is no need to worry about whether or not you need to macro quote them.

The IN operator does NOT need commas between the values. Spaces will work just fine, thank you!

 

/*intestinal infectious disease*/
%let int="001" "002" "003" "004" "005" "006" "007" "008" "009" ;
....
where code in (&int) 
....

Move things that do not change outside of the %DO loop and your code will be shorter and clearer and easier to debug.

 

Go ahead and use a few more macro variables to make the steps in the code a little clearer.  For example put the list of disease categories into a macro variable.  Then you can easily count how many there are instead of hard-coding the number 17.

 

%let disease_list=int zoo othbact hiv vir arth chly ricket spiro helminth para late;
	
/*intestinal infectious disease*/
%let int="001" "002" "003" "004" "005" "006" "007" "008" "009" ;
....
%do i=1 %to %sysfunc(countw(&disease_list));
  %let mvarname=%scan(&disease_list));
  %let code_list = &&&mvarname ;
...
where code in (&code_list)
...
%end;

 

 

Ask a Question
Discussion stats
  • 5 replies
  • 95 views
  • 0 likes
  • 6 in conversation