Desktop productivity for business analysts and programmers

ERROR 22-322: Syntax error; expecting a string but macro variable received is a string

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

ERROR 22-322: Syntax error; expecting a string but macro variable received is a string

Hi!

 

I am trying to figure out why my code is erroring out. I get the22-322 error saying that the referenced variable must be a quoted string, etc and will be ignored. But looking at the log, the macro variable referenced appears to be a quoted string. Can anyone tell me why this macro variable would not be read as a string? Or if I am missing something else?

 

TIN is a prompt input. The intention of the code is to accept multiple string values through a prompt, or if the prompt field is left blank, to refer to a CSV with a list of string values. If the prompt is left blank, the code works and references the CSV, however when prompt values are entered I get the following errors.

 

CODE:

%macro runPromptOrCSV;

%if &TIN_Count = 0 %then %do;

 

data work.PFMT_TIN_LIST;

infile "/opt/sas/modeldata/claimsanalytics/MCIUSIUAnalytics/BusAnlsts/&u_alias/TINRuns/TIN_List.csv" DSD dlm=',' lrecl= 10000 /*firstobs=2*/

 

;

length tin_list $9.

 

;

informat tin_list $9.

 

;

format tin_list $9.

 

;

input tin_list;

run;

PROC SQL;

CREATE TABLE WORK.UNIQUE_TIN_STR AS

SELECT DISTINCT /* TAX_ID */

("'" || STRIP( t1.tin_list) || "'") AS TAX_ID FROM WORK.PFMT_TIN_LIST t1 WHERE (LENGTH(t1.tin_list)) = 9;

 

QUIT;

PROC SQL NOPRINT;

SELECT DISTINCT TAX_ID

INTO :TINSrch SEPARATED BY ","

 

FROM WORK.UNIQUE_TIN_STR;

%PUT &TINSrch;

 

QUIT;

%end;

%else %do;

%macro promptList(

promptVar = /* specify the base name of the prompt to be made into a list */,

quotedList = yes /* individual items in list will be quoted if yes */,

listName = /* specify the name of the list to be created */

 

);

 

%* Build a list, named by the listName macro parameter of the prompt values selected. *;

%* The &promptVar._COUNT macro variable exists for multi-select macro prompts, so *;

%* loop through all the values selected - adding them to the list *;

%do i = 1 %to &&&promptVar._COUNT.;

%if &i. eq 1 %then

%let &listName. = %quote(%'&&&promptVar.%');

%else

%let &listName. = %unquote(&&&listName.,%quote(%'&&&promptVar&i.%'));

%end;

 

 

%let &listName. = %str(&&&listName.);

 

 

%mend promptList;

 

%promptList(

promptVar = TIN,

quotedList = yes /* individual items in list will be quoted if yes */,

listName = TINSrch

);

%end;

 

/*Matching TIN to SIU.CLM_PRTPT table*/

PROC SQL;

CREATE TABLE zPrtpt AS

SELECT t1.CLM_ID,

 

t1.PRTPT_ID,

t1.SSN_SIN_TIN,

t1.SRC_INSRT_TSTMP,

t1.SRC_RPLC_IND,

t1.SRC_SYS_DLTE_IND

FROM SIU.CLM_PRTPT_VW t1

/*WHERE %_eg_WhereParam( t1.SSN_SIN_TIN, TIN, IN, TYPE=S) AND (t1.SRC_RPLC_IND = 'N' AND t1.SRC_SYS_DLTE_IND = 'N');*/

WHERE t1.SSN_SIN_TIN IN (&TINSrch.) AND (t1.SRC_RPLC_IND = 'N' AND t1.SRC_SYS_DLTE_IND = 'N');

QUIT;

 

LOG:

1522 %runPromptOrCSV;

SYMBOLGEN: Macro variable TIN_COUNT resolves to 3

SYMBOLGEN: && resolves to &.

SYMBOLGEN: Macro variable PROMPTVAR resolves to TIN

SYMBOLGEN: Macro variable TIN_COUNT resolves to 3

SYMBOLGEN: Macro variable I resolves to 1

SYMBOLGEN: Macro variable LISTNAME resolves to TINSrch

SYMBOLGEN: && resolves to &.

SYMBOLGEN: Macro variable PROMPTVAR resolves to TIN

SYMBOLGEN: Macro variable TIN resolves to 822048096

SYMBOLGEN: Macro variable I resolves to 2

SYMBOLGEN: Macro variable LISTNAME resolves to TINSrch

SYMBOLGEN: && resolves to &.

SYMBOLGEN: Macro variable LISTNAME resolves to TINSrch

SYMBOLGEN: Macro variable TINSRCH resolves to '822048096'

SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.

SYMBOLGEN: && resolves to &.

SYMBOLGEN: Macro variable PROMPTVAR resolves to TIN

SYMBOLGEN: Macro variable I resolves to 2

28 The SAS System 07:58 Tuesday, July 24, 2018

SYMBOLGEN: Macro variable TIN2 resolves to 823849444

SYMBOLGEN: Macro variable I resolves to 3

SYMBOLGEN: Macro variable LISTNAME resolves to TINSrch

SYMBOLGEN: && resolves to &.

SYMBOLGEN: Macro variable LISTNAME resolves to TINSrch

SYMBOLGEN: Macro variable TINSRCH resolves to '822048096','823849444'

SYMBOLGEN: && resolves to &.

SYMBOLGEN: Macro variable PROMPTVAR resolves to TIN

SYMBOLGEN: Macro variable I resolves to 3

SYMBOLGEN: Macro variable TIN3 resolves to 364883108

SYMBOLGEN: Macro variable LISTNAME resolves to TINSrch

SYMBOLGEN: && resolves to &.

SYMBOLGEN: Macro variable LISTNAME resolves to TINSrch

SYMBOLGEN: Macro variable TINSRCH resolves to '822048096','823849444','364883108'

MPRINT(RUNPROMPTORCSV): ;

 

MPRINT(RUNPROMPTORCSV): PROC SQL;

NOTE: Line generated by the invoked macro "RUNPROMPTORCSV".

1522 CREATE TABLE zPrtpt AS SELECT t1.CLM_ID, t1.PRTPT_ID, t1.SSN_SIN_TIN,

1522 ! t1.SRC_INSRT_TSTMP, t1.SRC_RPLC_IND, t1.SRC_SYS_DLTE_IND FROM SIU.CLM_PRTPT_VW t1 WHERE

1522 ! t1.SSN_SIN_TIN IN (&TINSrch.) AND

_

22

76

WARNING: Apparent symbolic reference TINSRCH not resolved.

MPRINT(RUNPROMPTORCSV): CREATE TABLE zPrtpt AS SELECT t1.CLM_ID, t1.PRTPT_ID, t1.SSN_SIN_TIN, t1.SRC_INSRT_TSTMP,

t1.SRC_RPLC_IND, t1.SRC_SYS_DLTE_IND FROM SIU.CLM_PRTPT_VW t1 WHERE t1.SSN_SIN_TIN IN (&) AND (t1.SRC_RPLC_IND = 'N' AND

t1.SRC_SYS_DLTE_IND = 'N');

ERROR 22-322: Syntax error, expecting one of the following: a quoted string, a numeric constant, a datetime constant,

a missing value, (, -, SELECT.

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

NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.

MPRINT(RUNPROMPTORCSV): QUIT;


Accepted Solutions
Solution
3 weeks ago
Super User
Posts: 6,903

Re: ERROR 22-322: Syntax error; expecting a string but macro variable received is a string

Posted in reply to mnvandyke06

When SQL creates a macro variable using into : , it automatically places it in the local symbol table.  So within %PROMPTLIST, you have a value for &TINSrch but that value vanishes as soon as %PROMPTLIST finishes executing.

 

Add this statement before the SQL runs ... could be part of %PROMPTLIST or could be a stand-alone statement outside of all the macros:

 

%global TINSrch;

 

That probably handles the problem.

View solution in original post


All Replies
Solution
3 weeks ago
Super User
Posts: 6,903

Re: ERROR 22-322: Syntax error; expecting a string but macro variable received is a string

Posted in reply to mnvandyke06

When SQL creates a macro variable using into : , it automatically places it in the local symbol table.  So within %PROMPTLIST, you have a value for &TINSrch but that value vanishes as soon as %PROMPTLIST finishes executing.

 

Add this statement before the SQL runs ... could be part of %PROMPTLIST or could be a stand-alone statement outside of all the macros:

 

%global TINSrch;

 

That probably handles the problem.

New Contributor
Posts: 4

Re: ERROR 22-322: Syntax error; expecting a string but macro variable received is a string

Posted in reply to Astounding

Thanks so much! Worked perfectly Smiley Happy

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 100 views
  • 0 likes
  • 2 in conversation