BookmarkSubscribeRSS Feed
gbougalis
Calcite | Level 5

I am trying to run a Macro Program ; but am receiving these Errors : 

ERROR:22-322 and ERROR:76-322. According to my SAS LOG I have narrowed down the location of the error/errors in the Attached part of the Program. Any/all help would be greatly appreciated. I am attaching two separate screenshots : 1.) What my SAS LOG is showing me 2.) The piece of code associated with the error.  

NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
36         
37         %compare_all ;
37                 new_observations=case(memname)
                   ________________
                   22
                   76
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, >=, AND, EQ, EQT, GE, GET, 
              GT, GTT, LE, LET, LT, LTT, NE, NET, OR, WHEN, ^=, |, ||, ~=.  

ERROR 76-322: Syntax error, statement will be ignored.

Here is the part of the code/logic where the SAS LOG is telling me the error is occurring : 

update _var_obs_compare
           set lost_observations=case(memname)
             %do i = 1 %to &ndata;
                 when "%scan(&dlist,&i,|)" then &&removed&i;
			else . 
			%end ;			 
			new_observations=case(memname)
             %do i = 1 %to &ndata;
                 when "%scan(&dlist,&i,|)" then &&added&i;
			 else .  
			%end ; 
             data_changes=case(memname)
             %do i = 1 %to &ndata;
                 when "%scan(&dlist,&i,|)" then &&any_diff&i;
			else .  
			%end ; 
             id_variables=case(memname)
             %do i = 1 %to &ndata;
                 when "%scan(&dlist,&i,|)" then tranwrd("&&idlist&i",' ',', ');
			else '' 
			%end ;
	      update _var_attr_compare
           set data_changes=case(memname)
                   %do i = 1 %to &ndata;
                       when "%scan(&dlist,&i,|)" then case (upcase(name))
                           %if &&nvar&i>0 %then %do j = 1 %to &&nvar&i;
                               %if %sysevalf(%superq(any_diff&i._&j)^=,boolean) %then %do;
                                    when upcase("%scan(&&vlist&i,&j,|)") then %superq(any_diff&i._&j)
                               %end;
                           %end;
                           %else %do;
                              when "" then .
                           %end;
                            else . end
                   %end;
					else . end , 
                id_variables=case 
                       when upcase(name) in("" %do j = 1 %to %sysfunc(countw(&id,%str( ))); "%qupcase(%scan(&id,&j,%str( )))" %end;) then 'Yes'
                       else 'No' end;           
   quit;
16 REPLIES 16
AMSAS
SAS Super FREQ

Turn on the MPRINT MLOGIC SYMBOLGEN options 
Then run your code and review the log

You need to see what the macro compare_all is doing, because there is probably something prior to new_observations=case(memname) that is causing the issue (like a missing semi-colon)

gbougalis
Calcite | Level 5

After having added the : options symbolgen source mlogic mprint ; Statements the error is now showing up in two (2) places : 

SYMBOLGEN: Macro variable NDATA resolves to 0
MLOGIC(COMPARE_ALL): %DO loop beginning; index variable I; start value is 1; stop value is 0; by value is 1 Loop will not be
executed.
new_observations=case(memname)
_______________
22
76

And also here : 

SYMBOLGEN: Macro variable J resolves to 13
MLOGIC(COMPARE_ALL): %DO loop index variable J is now 14; loop will not iterate again.
MPRINT(COMPARE_ALL): update _var_obs_compare set lost_observations=case(memname) new_observations=case(memname)
data_changes=case(memname) id_variables=case(memname) update _var_attr_compare set data_changes=case(memname) else . end ,
id_variables=case when upcase(name) in("" "CORP_ENT_CD" "PROV_ORGZN_ID" "DW_MBR_KEY" "CAP_PMT_TYP_CD" "LST_NM" "FST_NM"
"HLTH_SYS_CNTRT_ID" "JOB_ID" "PD_CD" "PD_AMT" "BLUCAP_PROD_TYP" "XACTN_SRC_ID" "PRTNR_CLNT_SUPPSN_IND") then 'Yes' else 'No' end;
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, >=, AND, EQ, EQT, GE, GET,
GT, GTT, LE, LET, LT, LTT, NE, NET, OR, WHEN, ^=, |, ||, ~=.

ERROR 76-322: Syntax error, statement will be ignored.

AMSAS
SAS Super FREQ

You need to post the whole log, not just a small section.
Something is happening before the error that results in the error

 

For example in the log below notice that I'm missing a semi-colon after my set sashelp.class statement, which results in the error:

433  %macro error() ;
434      x=1 ;
435  %mend ;
436
437  data _null_ ;
438      set sashelp.class
439      %error();
NOTE: Line generated by the invoked macro "ERROR".
1         x=1 ;
           -
           22
           76
MPRINT(ERROR):   x=1 ;
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, (, -, :, ;,
              CUROBS, END, INDSNAME, KEY, KEYRESET, KEYS, NOBS, OPEN, POINT, _DATA_, _LAST_,
              _NULL_.

ERROR 76-322: Syntax error, statement will be ignored.

440  run ;
Tom
Super User Tom
Super User

Your macro seems to be trying to generate WHEN clauses in the middle of an SQL UPDATE statement.

update _var_obs_compare
  set lost_observations=case(memname)
%do i = 1 %to &ndata;
  when "%scan(&dlist,&i,|)" then &&removed&i;
  else . 
%end ;			 

The WHEN and ELSE keywords in SQL code need to be part of a CASE/END block of code.

Plus you cannot have the semi-colon after the resolution of &&REMOVED&I as that will end the UPDATE statement.

gbougalis
Calcite | Level 5

Tom, 

Wanted you to see the Errors in my SAS Log after having added the : OPTIONS SYMBOLGEN SOURCE MLOGIC MPRINT statements; as suggested by the AMSAS User above. 

SYMBOLGEN: Macro variable NDATA resolves to 0
The SAS System 08:30 Friday, January 21, 2022

MLOGIC(COMPARE_ALL): %DO loop beginning; index variable I; start value is 1; stop value is 0; by value is 1. Loop will not be
executed.
new_observations=case(memname)
________________
22
76

And I also see error here to, in the SAS Log : 

SYMBOLGEN: Macro variable J resolves to 13
MLOGIC(COMPARE_ALL): %DO loop index variable J is now 14; loop will not iterate again.
MPRINT(COMPARE_ALL): update _var_obs_compare set lost_observations=case(memname) new_observations=case(memname)
data_changes=case(memname) id_variables=case(memname) update _var_attr_compare set data_changes=case(memname) else . end ,
id_variables=case when upcase(name) in("" "CORP_ENT_CD" "PROV_ORGZN_ID" "DW_MBR_KEY" "CAP_PMT_TYP_CD" "LST_NM" "FST_NM"
"HLTH_SYS_CNTRT_ID" "JOB_ID" "PD_CD" "PD_AMT" "BLUCAP_PROD_TYP" "XACTN_SRC_ID" "PRTNR_CLNT_SUPPSN_IND") then 'Yes' else 'No' end;
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, *, **, +, -, /, <, <=, <>, =, >, >=, AND, EQ, EQT, GE, GET,
GT, GTT, LE, LET, LT, LTT, NE, NET, OR, WHEN, ^=, |, ||, ~=.

ERROR 76-322: Syntax error, statement will be ignored.

Tom
Super User Tom
Super User

I usually only turn on MLOGIC or SYMBOLGEN as a last resort when debugging a macro. Otherwise the SAS log is too clutter for humans to decipher.

So your macro generated this statement.

update _var_obs_compare
 set lost_observations=case(memname)
  new_observations=case(memname)
  data_changes=case(memname)
  id_variables=case(memname)
 update _var_attr_compare 
 set data_changes=case(memname) 
 else . end 
,
  id_variables=case 
  when upcase(name) in("" "CORP_ENT_CD" "PROV_ORGZN_ID" "DW_MBR_KEY" "CAP_PMT_TYP_CD" "LST_NM" "FST_NM"
"HLTH_SYS_CNTRT_ID" "JOB_ID" "PD_CD" "PD_AMT" "BLUCAP_PROD_TYP" "XACTN_SRC_ID" "PRTNR_CLNT_SUPPSN_IND") 
  then 'Yes' else 'No' end
;

That does not look like valid SQL to me.

What SQL code were you trying to generate?

gbougalis
Calcite | Level 5

Tom, 

Did you want me to forward just that section of the PROC SQL code/logic; where the Error is occurring ? Or, the entire piece ?

Tom
Super User Tom
Super User

I need to know what you trying to do.

 

Before you can use macro logic to generate SAS code you need to know what SAS code you will want it to generate.

 

So show what SAS code you need to generate.

 

Did the macro code ever work to generate that SAS code?  If so then what changed to make it stop working?

 

gbougalis
Calcite | Level 5

Tom, 

I am trying to run this entire program macro program which compares the datasets of two libraries together to check for changes in variables, datasets, and values in datasets the two libraries share. The macro outputs a report of three levels into an Excel file. I have never run this program successfully. I am attaching the entire piece of code/logic in this reply to you. 

gbougalis
Calcite | Level 5
Just taking a wild guess here , but after looking at the SAS Log where the Error was occurring and looking at the code/logic above - shouldn't the Statement values have commas between then since this is an "in" statement . id_variables=case
when upcase(name) in("" "CORP_ENT_CD" "PROV_ORGZN_ID" "DW_MBR_KEY" "CAP_PMT_TYP_CD" "LST_NM" "FST_NM"
"HLTH_SYS_CNTRT_ID" "JOB_ID" "PD_CD" "PD_AMT" "BLUCAP_PROD_TYP" "XACTN_SRC_ID" "PRTNR_CLNT_SUPPSN_IND")
then 'Yes' else 'No' end
Tom
Super User Tom
Super User

The IN operator does not need commas. Spaces work fine.

Try it.

proc print data=sashelp.class;
 where name in: ('A' 'B') ;
run;
gbougalis
Calcite | Level 5

Just taking a wild guess here , but after looking at the SAS Log where the Error was occurring and looking at the code/logic above - shouldn't the Statement values have commas between then since this is an "in" statement . id_variables=case
when upcase(name) in("" "CORP_ENT_CD" "PROV_ORGZN_ID" "DW_MBR_KEY" "CAP_PMT_TYP_CD" "LST_NM" "FST_NM"
"HLTH_SYS_CNTRT_ID" "JOB_ID" "PD_CD" "PD_AMT" "BLUCAP_PROD_TYP" "XACTN_SRC_ID" "PRTNR_CLNT_SUPPSN_IND")
then 'Yes' else 'No' end

gbougalis
Calcite | Level 5
Just taking a wild guess here , but after looking at the SAS Log where the Error was occurring and looking at the code/logic above - shouldn't the Statement values have commas between then since this is an "in" statement . id_variables=case
when upcase(name) in("" "CORP_ENT_CD" "PROV_ORGZN_ID" "DW_MBR_KEY" "CAP_PMT_TYP_CD" "LST_NM" "FST_NM"
"HLTH_SYS_CNTRT_ID" "JOB_ID" "PD_CD" "PD_AMT" "BLUCAP_PROD_TYP" "XACTN_SRC_ID" "PRTNR_CLNT_SUPPSN_IND")
then 'Yes' else 'No' end
Tom
Super User Tom
Super User

Did someone give you this macro? Did it work for them?

 

What is the purpose.

The top seems to be comparing the structure of two sets of datasets by looking at the output of PROC CONTENTS.

What is the part that is breaking trying to do?  The code does not really say why it is doing whatever it is trying to do.

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!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 16 replies
  • 2707 views
  • 0 likes
  • 4 in conversation