BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
manya92
Fluorite | Level 6

Hi all, I am running this code but its giving me 5 errors. I have attached both my code and my log for your reference

 

option mprint mlogic symbolgen ;

*STEP 1 ;

/*CALCUALTING THE NUMBER OF PATIENTS WITH THE APPLICABLE ENDPOINT (ONLY FIRST EVENT TO BE COUNTED) */

/*FLAG COMORBIDITIES  */

%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");
		
	%end ;
	
	
	/*FLAG PATIENT WITH THE ABOVE MENTIONED COMORBIDITIES ATFTER INDEX_DATE BUT BEFORE PERIOD_STOP*/;
	data _04_postindex_&inf. ;
		set derived._01_cohort1_final ;
		&&inf. =1 ;
		where (code in:(&&inf.)) and (index_date le svcdate le period stop) ;
	run ;
	
	proc sort data = _04_como ;
		by enrolid index_date svcdate ;
	run ;
	
	data _04_como1;
		set _04_como ;
		by enrolid svcdate ;
		format first_svcdate_&inf. mmddyy10. ;
		if first.enrolid then first_svcdate_&inf. = svcdate ;
	run ;
	
	/*FLAG PATIENTS WITH THE ABOVE MENTIONED COMORBIDITES BEFORE THE INDEX_DATE */
	
%mend incidence;
%incidence;
	

The log looks like this 

 
 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 SYMBOLGEN:  Macro variable _SASWSTEMP_ resolves to /data1/home/genesis/sai/.sasstudio/.images/43c9110e-7028-4ff4-bfa0-9eccf8c103bb
 SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted for printing.
 SYMBOLGEN:  Macro variable GRAPHINIT resolves to GOPTIONS RESET=ALL GSFNAME=_GSFNAME;

 91         option mprint mlogic symbolgen ;
 92         
 93         *STEP 1 ;
 94         
 95         /*CALCUALTING THE NUMBER OF PATIENTS WITH THE APPLICABLE ENDPOINT (ONLY FIRST EVENT TO BE COUNTED) */
 96         
 97         /*FLAG COMORBIDITIES  */
 98         
 99         %macro incidence ;
 100        
 101        %do i = 1 %to 12 ;
 102        
 103        %let inf = %scan(int*zoo*othbact*hiv*vir*arth*chly*ricket*spiro*helminth*para*late, &i., *) ;
 104        
 105        /*intestinal infectious disease*/
 106        %let int = %str("001","002","003","004","005","006","007","008","009") ;
 107        
 108        /*zoonotic bacterial disease*/
 109        %let zoo = %str("020","021","022","023","024","025","026","027") ;
 110        
 111        /*other bacterial disease*/
 112        %let othbact = %str("030","031","032","033","034","035","036","037","038","039","040","041");
 113        
 114        /*hiv*/
 115        %let hiv = %str("042") ;
 116        
 117        /*viral diseases accompanied by exanthem*/
 118        %let vir = %str("050","051","052","053","054","055","056","057");
 119        
 120        /*arthropod-brone viral disease*/
 121        %let arth = %str("060","061","062","063","064","065","066");
 122        
 123        /*other diseases due to viruses and chlamydiae*/
 124        %let chly = %str("070","071","072","073","074","075","076","077","078","079");
 125        
 126        /*rickettsioses and otehr arthrpod-borne diseases*/
 127        %let ricket = %str("080","081","082","083","084","085","086","087","088");
 128        
 129        /*other spirochetal diseases*/
 130        %let spiro = %str("100","101","102","103","104");
 131        
 132        /*helminthiases*/
 133        %let helminth = %str("120","121","123","124","125","126","127","128","129");
 134        
 135        /*other infectious and parasitic diseases*/
 136        %let para = %str("130","131","132","133","134","135","136");
 137        
 138        /*late effects of infectious and parasitic diseases*/
 139        %let late = %str("137","138","139");
 140        
 141        %end ;
 142        
 143        
 144        /*FLAG PATIENT WITH THE ABOVE MENTIONED COMORBIDITIES ATFTER INDEX_DATE BUT BEFORE PERIOD_STOP*/;
 145        data _04_postindex_&inf. ;
 146        set derived._01_cohort1_final ;
 147        &&inf. =1 ;
 148        where (code in:(&&inf.)) and (index_date le svcdate le period stop) ;
 149        run ;
 150        
 151        proc sort data = _04_como ;
 152        by enrolid index_date svcdate ;
 153        run ;
 154        
 155        data _04_como1;
 156        set _04_como ;
 157        by enrolid svcdate ;
 158        format first_svcdate_&inf. mmddyy10. ;
 159        if first.enrolid then first_svcdate_&inf. = svcdate ;
 160        run ;
 161        
 162        /*FLAG PATIENTS WITH THE ABOVE MENTIONED COMORBIDITES BEFORE THE INDEX_DATE */
 163        
 164        %mend incidence;
 165        %incidence;
 MLOGIC(INCIDENCE):  Beginning execution.
 MLOGIC(INCIDENCE):  %DO loop beginning; index variable I; start value is 1; stop value is 12; by value is 1.  
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 1
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 2; loop will iterate again.
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 2
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 3; loop will iterate again.
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 3
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 4; loop will iterate again.
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 4
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 5; loop will iterate again.
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 5
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 6; loop will iterate again.
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 6
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 7; loop will iterate again.
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 7
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 8; loop will iterate again.
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 8
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 9; loop will iterate again.
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 9
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 10; loop will iterate again.
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 10
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 11; loop will iterate again.
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 11
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 12; loop will iterate again.
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 12
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 13; loop will not iterate again.
 MPRINT(INCIDENCE):   ;
 SYMBOLGEN:  Macro variable INF resolves to late
 MPRINT(INCIDENCE):   data _04_postindex_late ;
 MPRINT(INCIDENCE):   set derived._01_cohort1_final ;
 NOTE: Data file DERIVED._01_COHORT1_FINAL.DATA is in a format that is native to another host, or the file encoding does not match 
       the session encoding. Cross Environment Data Access will be used, which might require additional CPU resources and might 
       reduce performance.
 SYMBOLGEN:  && resolves to &.
 SYMBOLGEN:  Macro variable INF resolves to late
 MPRINT(INCIDENCE):   late =1 ;
 SYMBOLGEN:  && resolves to &.
 SYMBOLGEN:  Macro variable INF resolves to late
 NOTE: Line generated by the macro variable "INF".
 165        late
            ____
            22
            76
 MPRINT(INCIDENCE):   where (code in:(late)) and (index_date le svcdate le period stop) ;
 ERROR: Syntax error while parsing WHERE clause.
 MPRINT(INCIDENCE):   run ;
 
 ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant, a datetime constant, 
               a missing value, -.  
 
 ERROR 76-322: Syntax error, statement will be ignored.
 
 NOTE: The SAS System stopped processing this step because of errors.
 WARNING: The data set WORK._04_POSTINDEX_LATE may be incomplete.  When this step was stopped there were 0 observations and 9 
          variables.
 WARNING: Data set WORK._04_POSTINDEX_LATE was not replaced because this step was stopped.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.01 seconds
       
 
 MPRINT(INCIDENCE):   proc sort data = _04_como ;
 ERROR: File WORK._04_COMO.DATA does not exist.
 MPRINT(INCIDENCE):   by enrolid index_date svcdate ;
 MPRINT(INCIDENCE):   run ;
 
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: PROCEDURE SORT used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 MPRINT(INCIDENCE):   data _04_como1;
 MPRINT(INCIDENCE):   set _04_como ;
 ERROR: File WORK._04_COMO.DATA does not exist.
 MPRINT(INCIDENCE):   by enrolid svcdate ;
 SYMBOLGEN:  Macro variable INF resolves to late
 MPRINT(INCIDENCE):   format first_svcdate_late mmddyy10. ;
 SYMBOLGEN:  Macro variable INF resolves to late
 MPRINT(INCIDENCE):   if first.enrolid then first_svcdate_late = svcdate ;
 MPRINT(INCIDENCE):   run ;
 
 NOTE: The SAS System stopped processing this step because of errors.
 WARNING: The data set WORK._04_COMO1 may be incomplete.  When this step was stopped there were 0 observations and 2 variables.
 WARNING: Data set WORK._04_COMO1 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
       
 
 MLOGIC(INCIDENCE):  Ending execution.
 166        
 167        
 168        
 169        
 170        
 171        
 172        
 173        
 174        
 175        
 176        
 177        
 178        
 179        
 180        OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 SYMBOLGEN:  Macro variable GRAPHTERM resolves to GOPTIONS NOACCESSIBLE;
 193        

Any help is appreciated

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Look at just this much of your code:

 

data _04_postindex_&inf. ;
set derived._01_cohort1_final ;
&&inf. =1 ;
where (code in:(&&inf.)) and (index_date le svcdate le period stop) ;
run ;
 

 

Whatever &&inf. resolves into, you will always get an error.  There is no way you could take any possible set of characters, plug it into both of these statements, and have it form a working program:


&&inf. =1 ;
where (code in:(&&inf.)) and (index_date le svcdate le period stop) ;

 

I suspect you should be changing the number of ampersands in both places:


&inf. =1 ;
where (code in:(&&&inf.)) and (index_date le svcdate le period stop) ;

 

Try it and see what you get.

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

Macros have to produce valid SAS code.

 

(code in:(late))

 

This is not valid code in a where statement.

--
Paige Miller
Astounding
PROC Star

Look at just this much of your code:

 

data _04_postindex_&inf. ;
set derived._01_cohort1_final ;
&&inf. =1 ;
where (code in:(&&inf.)) and (index_date le svcdate le period stop) ;
run ;
 

 

Whatever &&inf. resolves into, you will always get an error.  There is no way you could take any possible set of characters, plug it into both of these statements, and have it form a working program:


&&inf. =1 ;
where (code in:(&&inf.)) and (index_date le svcdate le period stop) ;

 

I suspect you should be changing the number of ampersands in both places:


&inf. =1 ;
where (code in:(&&&inf.)) and (index_date le svcdate le period stop) ;

 

Try it and see what you get.

manya92
Fluorite | Level 6

When i run with your corrections. I get this 

 
 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 SYMBOLGEN:  Macro variable _SASWSTEMP_ resolves to /data1/home/genesis/sai/.sasstudio/.images/7a76e0a9-a23c-4470-9071-c0251fef858c
 SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted for printing.
 SYMBOLGEN:  Macro variable GRAPHINIT resolves to GOPTIONS RESET=ALL GSFNAME=_GSFNAME;
 7
 91         option mprint mlogic symbolgen ;
 92         
 93         *STEP 1 ;
 94         
 95         /*CALCUALTING THE NUMBER OF PATIENTS WITH THE APPLICABLE ENDPOINT (ONLY FIRST EVENT TO BE COUNTED) */
 96         
 97         /*FLAG COMORBIDITIES  */
 98         
 99         %macro incidence ;
 100        
 101        %do i = 1 %to 12 ;
 102        
 103        %let inf = %scan(int*zoo*othbact*hiv*vir*arth*chly*ricket*spiro*helminth*para*late, &i., *) ;
 104        
 105        /*intestinal infectious disease*/
 106        %let int = %str("001","002","003","004","005","006","007","008","009") ;
 107        
 108        /*zoonotic bacterial disease*/
 109        %let zoo = %str("020","021","022","023","024","025","026","027") ;
 110        
 111        /*other bacterial disease*/
 112        %let othbact = %str("030","031","032","033","034","035","036","037","038","039","040","041");
 113        
 114        /*hiv*/
 115        %let hiv = %str("042") ;
 116        
 117        /*viral diseases accompanied by exanthem*/
 118        %let vir = %str("050","051","052","053","054","055","056","057");
 119        
 120        /*arthropod-brone viral disease*/
 121        %let arth = %str("060","061","062","063","064","065","066");
 122        
 123        /*other diseases due to viruses and chlamydiae*/
 124        %let chly = %str("070","071","072","073","074","075","076","077","078","079");
 125        
 126        /*rickettsioses and otehr arthrpod-borne diseases*/
 127        %let ricket = %str("080","081","082","083","084","085","086","087","088");
 128        
 129        /*other spirochetal diseases*/
 130        %let spiro = %str("100","101","102","103","104");
 131        
 132        /*helminthiases*/
 133        %let helminth = %str("120","121","123","124","125","126","127","128","129");
 134        
 135        /*other infectious and parasitic diseases*/
 136        %let para = %str("130","131","132","133","134","135","136");
 137        
 138        /*late effects of infectious and parasitic diseases*/
 139        %let late = %str("137","138","139");
 140        
 141        %end ;
 142        
 143        
 144        /*FLAG PATIENT WITH THE ABOVE MENTIONED COMORBIDITIES ATFTER INDEX_DATE BUT BEFORE PERIOD_STOP*/;
 145        data _04_postindex_&inf. ;
 146        set derived._01_cohort1_final ;
 147        &inf. =1 ;
 148        where (code in:(&&&inf.)) and (index_date le svcdate le period stop) ;
 149        run ;
 150        
 151        proc sort data = _04_como ;
 152        by enrolid index_date svcdate ;
 153        run ;
 154        
 155        data _04_como1;
 156        set _04_como ;
 157        by enrolid svcdate ;
 158        format first_svcdate_&inf. mmddyy10. ;
 159        if first.enrolid then first_svcdate_&inf. = svcdate ;
 160        run ;
 161        
 162        /*FLAG PATIENTS WITH THE ABOVE MENTIONED COMORBIDITES BEFORE THE INDEX_DATE */
 163        
 164        %mend incidence;
 165        %incidence;
 MLOGIC(INCIDENCE):  Beginning execution.
 MLOGIC(INCIDENCE):  %DO loop beginning; index variable I; start value is 1; stop value is 12; by value is 1.  
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 1
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 2; loop will iterate again.
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 2
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 3; loop will iterate again.
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 3
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 4; loop will iterate again.
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 4
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 5; loop will iterate again.
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 5
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 6; loop will iterate again.
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 6
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 7; loop will iterate again.
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 7
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 8; loop will iterate again.
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 8
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 9; loop will iterate again.
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 9
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 10; loop will iterate again.
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 10
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 11; loop will iterate again.
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 11
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 12; loop will iterate again.
 MLOGIC(INCIDENCE):  %LET (variable name is INF)
 SYMBOLGEN:  Macro variable I resolves to 12
 MLOGIC(INCIDENCE):  %LET (variable name is INT)
 MLOGIC(INCIDENCE):  %LET (variable name is ZOO)
 MLOGIC(INCIDENCE):  %LET (variable name is OTHBACT)
 MLOGIC(INCIDENCE):  %LET (variable name is HIV)
 MLOGIC(INCIDENCE):  %LET (variable name is VIR)
 MLOGIC(INCIDENCE):  %LET (variable name is ARTH)
 MLOGIC(INCIDENCE):  %LET (variable name is CHLY)
 MLOGIC(INCIDENCE):  %LET (variable name is RICKET)
 MLOGIC(INCIDENCE):  %LET (variable name is SPIRO)
 MLOGIC(INCIDENCE):  %LET (variable name is HELMINTH)
 MLOGIC(INCIDENCE):  %LET (variable name is PARA)
 MLOGIC(INCIDENCE):  %LET (variable name is LATE)
 MLOGIC(INCIDENCE):  %DO loop index variable I is now 13; loop will not iterate again.
 MPRINT(INCIDENCE):   ;
 SYMBOLGEN:  Macro variable INF resolves to late
 MPRINT(INCIDENCE):   data _04_postindex_late ;
 MPRINT(INCIDENCE):   set derived._01_cohort1_final ;
 NOTE: Data file DERIVED._01_COHORT1_FINAL.DATA is in a format that is native to another host, or the file encoding does not match 
       the session encoding. Cross Environment Data Access will be used, which might require additional CPU resources and might 
       reduce performance.
 SYMBOLGEN:  Macro variable INF resolves to late
 MPRINT(INCIDENCE):   late =1 ;
 SYMBOLGEN:  && resolves to &.
 SYMBOLGEN:  Macro variable INF resolves to late
 SYMBOLGEN:  Macro variable LATE resolves to "137","138","139"
 SYMBOLGEN:  Some characters in the above value which were subject to macro quoting have been unquoted for printing.
 22: LINE and COLUMN cannot be determined.
 NOTE 242-205: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
 ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, >=, AND, EQ, GE, GT, LE, LT, 
               NE, OR, ^=, |, ||, ~=.  
 76: 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 76-322: Syntax error, statement will be ignored.
 MPRINT(INCIDENCE):   where (code in:("137","138","139")) and (index_date le svcdate le period stop) ;
 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_POSTINDEX_LATE may be incomplete.  When this step was stopped there were 0 observations and 9 
          variables.
 WARNING: Data set WORK._04_POSTINDEX_LATE was not replaced because this step was stopped.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.01 seconds
       
 
 MPRINT(INCIDENCE):   proc sort data = _04_como ;
 ERROR: File WORK._04_COMO.DATA does not exist.
 MPRINT(INCIDENCE):   by enrolid index_date svcdate ;
 MPRINT(INCIDENCE):   run ;
 
 NOTE: The SAS System stopped processing this step because of errors.
 NOTE: PROCEDURE SORT used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 MPRINT(INCIDENCE):   data _04_como1;
 MPRINT(INCIDENCE):   set _04_como ;
 ERROR: File WORK._04_COMO.DATA does not exist.
 MPRINT(INCIDENCE):   by enrolid svcdate ;
 SYMBOLGEN:  Macro variable INF resolves to late
 MPRINT(INCIDENCE):   format first_svcdate_late mmddyy10. ;
 SYMBOLGEN:  Macro variable INF resolves to late
 MPRINT(INCIDENCE):   if first.enrolid then first_svcdate_late = svcdate ;
 MPRINT(INCIDENCE):   run ;
 
 NOTE: The SAS System stopped processing this step because of errors.
 WARNING: The data set WORK._04_COMO1 may be incomplete.  When this step was stopped there were 0 observations and 2 variables.
 WARNING: Data set WORK._04_COMO1 was not replaced because this step was stopped.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.01 seconds
       
 
 MLOGIC(INCIDENCE):  Ending execution.
 166        
 167        
 168        
 169        
 170        
 171        
 172        
 173        
 174        
 175        
 176        
 177        
 178        
 179        
 180        OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 SYMBOLGEN:  Macro variable GRAPHTERM resolves to GOPTIONS NOACCESSIBLE;
 193        
Astounding
PROC Star

Yes, WHERE statements can have trouble unquoting in time.  You have applied the %STR function unnecessarily many times:

 

%let int = %str("001","002","003","004","005","006","007","008","009") ;

 

Get rid of %STR so this statement becomes:

 

%let int = "001","002","003","004","005","006","007","008","009";

 

There are many other such cases.  Keep %SCAN, but get rid of %STR in all the %LET statements.

Reeza
Super User
	data _04_postindex_late ;
		set derived._01_cohort1_final ;
		late =1 ;
		where (code in:(late)) and (index_date le svcdate le period stop) ;
	run ;

 

What happens if you run the above outside of the macro?

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1272 views
  • 0 likes
  • 4 in conversation