Hello, I'm getting the following ERROR 22-322: Expecting a name. First set of code works fine, second set of code throwing an error. I want to get away from having to enter the value in manually.
My code that work:
/*******************************************************************************/
/*** Macro variables used for output file name and new column in file ***/
/*******************************************************************************/
%let DataDte='EOD 12-27'n;
.
.
proc sql;
create table Program_Issues_EMRO1 as
select
'Enterprise' as Team
,'EMRO-HLS' as Role
,EMRO as Name
,'Active + Inactive Model Count' as Catageory
,count(*) as &DataDte
from DetailData1
Group by 1, 2, 3, 4;
quit;
My code that does not work:
&columndt is a macro variable that contains 'EOD 12-27'n . What is the issue, seems to be the same value.
/*******************************************************************************/
/*** Macro variables used for output file name and new column in file ***/
/*******************************************************************************/
%let DataDte=&columndt;
.
.
proc sql;
create table Program_Issues_EMRO1 as
select
'Enterprise' as Team
,'EMRO-HLS' as Role
,EMRO as Name
,'Active + Inactive Model Count' as Catageory
,count(*) as &DataDte
from DetailData1
Group by 1, 2, 3, 4;
quit;
It sounds like you have a macro quoting problem. My guess is that the COLUMNDT variable was constructed something like
%let ColumnDt=%str(%'&someothervariable%'n);
The SAS processor cannot understand that quoted value as a name. I can replicate your error like this:
%let x=%str(%' x value%'n);
%put &x;
proc sql;
select name as &x from sashelp.class;
quit;
but when I use %unquote(&x) instead of &x (as suggested by @gamotte ), the program works OK.
If you are using the DataDte variable in many places, you may want to do the %unquoting there:
%let DataDte=%unquote(&ColumnDt);
and then leave the rest of your program unchanged.
Or you can do the unquoting on the original ColumnDt variable, if that makes for better code.
Please add
options mprint symbolgen;
to your code, and then post the complete log from it by copy/pasting into a window opened with the </> button.
See snippet of the log. Not able to attach the entire log as it 3 MB and would trigger a security event.
SYMBOLGEN: Macro variable HLDDATE resolves to 'EOD 12-27'n
SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.
'EOD 12-27'n
SYMBOLGEN: Macro variable HLDDATE resolves to 'EOD 12-27'n
SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.
SYMBOLGEN: Macro variable DATADTE resolves to 'EOD 12-27'n
SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.
'EOD 12-27'n
SYMBOLGEN: Macro variable FILEDT resolves to 20201227
SYMBOLGEN: Macro variable PATH1 resolves to /users/emrmra/Dwight/Daily Monitoring and Escalation Report
SYMBOLGEN: Macro variable DATADTE2 resolves to 20201227
SYMBOLGEN: Macro variable HISDATA resolves to Cw3000
SYMBOLGEN: Macro variable DATADTE resolves to 'EOD 12-27'n
SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.
_
22
76
ERROR 22-322: Expecting a name.
ERROR 76-322: Syntax error, statement will be ignored.
SYMBOLGEN: Macro variable DATADTE resolves to 'EOD 12-27'n
SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.
This code
%let DataDte=&columndt;
.
.
proc sql;
create table Program_Issues_EMRO1 as
select
'Enterprise' as Team
,'EMRO-HLS' as Role
,EMRO as Name
,'Active + Inactive Model Count' as Catageory
,count(*) as &DataDte
from DetailData1
Group by 1, 2, 3, 4;
quit;
CANNOT produce a 3 MB log. If it hits a syntax ERROR, the log will in fact be very short.
Correct that is only a sample of the code. The entire code is 15000+ lines.
‘EOD 12-25’ will be used as an alias for the count(*) in the SQL, so it would become a variable name. As mentioned previously if I use %let DataDte = ‘EOD 12-25’n it works. It fails when I replace ‘EOD 12-25’ with a macro variable with same value.
Code that work:
/*******************************************************************************/
/*** Macro variables used for output file name and new column in file ***/
/*******************************************************************************/
%let DataDte='EOD 12-27'n;
.
.
proc sql;
create table Program_Issues_EMRO1 as
select
'Enterprise' as Team
,'EMRO-HLS' as Role
,EMRO as Name
,'Active + Inactive Model Count' as Catageory
,count(*) as &DataDte
from DetailData1
Group by 1, 2, 3, 4;
quit;
Code does not work:
&columndt is a macro variable that contains 'EOD 12-27'n . What is the issue, seems to be the same value.
/*******************************************************************************/
/*** Macro variables used for output file name and new column in file ***/
/*******************************************************************************/
%let DataDte=&columndt;
.
.
proc sql;
create table Program_Issues_EMRO1 as
select
'Enterprise' as Team
,'EMRO-HLS' as Role
,EMRO as Name
,'Active + Inactive Model Count' as Catageory
,count(*) as &DataDte
from DetailData1
Group by 1, 2, 3, 4;
quit;
Please run this code (and nothing else)
%let DataDte=&columndt;
proc sql;
create table Program_Issues_EMRO1 as
select
'Enterprise' as Team
,'EMRO-HLS' as Role
,EMRO as Name
,'Active + Inactive Model Count' as Catageory
,count(*) as &DataDte
from DetailData1
Group by 1, 2, 3, 4;
quit;
so we can localize the problem.
Had to add additional code to bring in data. Below code got error
options mlogic mprint merror nosource nonotes missing=0 symbolgen;
%put _automatic_;
libname Myfiles '/users/emrmra/Dwight/Daily Monitoring and Escalation Report';
%let path1=/users/emrmra/Dwight/Daily Monitoring and Escalation Report;
%let path2=/users/emrmra/Dwight/Daily Monitoring and Escalation Report;
/*******************************************************************************/
/*** Macro variables used for output file name and new column in file ***/
/*******************************************************************************/
%let columndt=EOD 12-27;
%let filedt = 20201227;
%put &columndt.;
%let HldDate=%str(%')%trim(&columndt)%str(%')n;
%put &HldDate.;
%let DataDte=&HldDate;
%put &DataDte.;
%let DataDte2=&filedt;
%let hisdata=Cw3000;
/*******************************************************************************/
/*** Importing Inventory file from DMER ***/
/*******************************************************************************/
proc import out=dir
datafile="&path1/Daily Monitoring and Escalation Report_Enterprise.&DataDte2..xlsx"
dbms=xlsx replace;
getnames=yes;
range="Inventory$A2:&hisdata.";
run;
/*******************************************************************************/
/*** Filtering DMER Inventory for CCAR only ***/
/*******************************************************************************/
Data DetailData1;
set Dir;
if 'Used in CCAR'n = 'Y';
length EMRO $40.;
EMRO = 'Doe, John';
run;
/*******************************************************************************/
/*** Creating the different metrics (EMRO, MRO, MVL levels) ***/
/*******************************************************************************/
proc sql;
create table Program_Issues_EMRO1 as
select
'Enterprise' as Team
,'EMRO-HLS' as Role
,EMRO as Name
,'Active + Inactive Model Count' as Catageory
,count(*) as &DataDte
from DetailData1
Group by 1, 2, 3, 4;
quit;
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
INFO: Character variables have defaulted to a length of 200 at the places given by: (Line):(Column). Truncation can result.
40:1 RC
SYMBOLGEN: Macro variable _SASWSTEMP_ resolves to /home/nbddqv2/.sasstudio/.images/00f84f34-44fe-4040-8412-6af524637b24
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;
72
73 options mlogic mprint merror nosource nonotes missing=0 symbolgen;
AUTOMATIC AFDSID 0
AUTOMATIC AFDSNAME
AUTOMATIC AFLIB
AUTOMATIC AFSTR1
AUTOMATIC AFSTR2
AUTOMATIC FSPBDV
AUTOMATIC SYSADDRBITS 64
AUTOMATIC SYSBUFFR
AUTOMATIC SYSCC 0
AUTOMATIC SYSCHARWIDTH 1
AUTOMATIC SYSCMD
AUTOMATIC SYSDATASTEPPHASE
AUTOMATIC SYSDATE 28DEC20
AUTOMATIC SYSDATE9 28DEC2020
AUTOMATIC SYSDAY Monday
AUTOMATIC SYSDEVIC
AUTOMATIC SYSDMG 0
AUTOMATIC SYSDSN WORK PROGRAM_ISSUES_EMRO1
AUTOMATIC SYSENCODING latin1
AUTOMATIC SYSENDIAN LITTLE
AUTOMATIC SYSENV BACK
AUTOMATIC SYSERR 0
AUTOMATIC SYSERRORTEXT 76-322: Syntax error, statement will be ignored.
AUTOMATIC SYSFILRC 0
AUTOMATIC SYSHOSTINFOLONG Linux LIN X64 3.10.0-1160.2.2.el7.x86_64 #1 SMP Sat Oct 17 05:06:47 UTC 2020 x86_64 Red Hat Enterprise
Linux Server release 7.9 (Maipo)
AUTOMATIC SYSHOSTNAME lrdna455papdri
AUTOMATIC SYSINCLUDEFILEDEVICE
AUTOMATIC SYSINCLUDEFILEDIR
AUTOMATIC SYSINCLUDEFILEFILEREF
AUTOMATIC SYSINCLUDEFILENAME
AUTOMATIC SYSINDEX 18
AUTOMATIC SYSINFO 0
AUTOMATIC SYSJOBID 18312
AUTOMATIC SYSLAST WORK.PROGRAM_ISSUES_EMRO1
AUTOMATIC SYSLCKRC 0
AUTOMATIC SYSLIBRC 0
AUTOMATIC SYSLOGAPPLNAME
AUTOMATIC SYSMACRONAME
AUTOMATIC SYSMAXLONG 9007199254740992
AUTOMATIC SYSMENV S
AUTOMATIC SYSMSG
AUTOMATIC SYSNCPU 16
AUTOMATIC SYSNOBS 1811
AUTOMATIC SYSODSESCAPECHAR 03
AUTOMATIC SYSODSGRAPHICS 1
AUTOMATIC SYSODSPATH WORK.TEMPLAT(UPDATE) SASUSER.TEMPLAT(READ) SASHELP.TMPLMST(READ)
AUTOMATIC SYSPARM
AUTOMATIC SYSPRINTTOLOG
AUTOMATIC SYSPRINTTOLIST
AUTOMATIC SYSPROCESSID 41DCAE80A8785ACD4018000000000000
AUTOMATIC SYSPROCESSMODE SAS Workspace Server
AUTOMATIC SYSPROCESSNAME Object Server
AUTOMATIC SYSPROCNAME
AUTOMATIC SYSRC 0
AUTOMATIC SYSSCP LIN X64
AUTOMATIC SYSSCPL Linux
AUTOMATIC SYSSITE 70132342
AUTOMATIC SYSSIZEOFLONG 8
AUTOMATIC SYSSIZEOFPTR 8
AUTOMATIC SYSSIZEOFUNICODE 4
AUTOMATIC SYSSTARTID
AUTOMATIC SYSSTARTNAME
AUTOMATIC SYSTCPIPHOSTNAME lrdna455papdri.usrdnwx.amrs.bankofamerica.com
AUTOMATIC SYSTIME 16:43
AUTOMATIC SYSTIMEZONE GMT-05:00
AUTOMATIC SYSTIMEZONEIDENT ETC/GMT+5
AUTOMATIC SYSTIMEZONEOFFSET -18000
AUTOMATIC SYSUSERID nbddqv2
AUTOMATIC SYSVER 9.4
AUTOMATIC SYSVLONG 9.04.01M6P110718
AUTOMATIC SYSVLONG4 9.04.01M6P11072018
AUTOMATIC SYSWARNINGTEXT The data set WORK.DETAILDATA1 may be incomplete. When this step was stopped there were 0 observations and
2 variables.
SYMBOLGEN: Macro variable COLUMNDT resolves to EOD 12-27
EOD 12-27
MLOGIC(TRIM): Beginning execution.
MLOGIC(TRIM): This macro was compiled from the autocall file /sasgrid/prd/sashome/SASFoundation/9.4/sasautos/trim.sas
SYMBOLGEN: Macro variable COLUMNDT resolves to EOD 12-27
MLOGIC(TRIM): Parameter VALUE has value EOD 12-27
MLOGIC(TRIM): %LOCAL I
SYMBOLGEN: Macro variable VALUE resolves to EOD 12-27
MLOGIC(TRIM): %DO loop beginning; index variable I; start value is 9; stop value is 1; by value is -1.
SYMBOLGEN: Macro variable VALUE resolves to EOD 12-27
SYMBOLGEN: Macro variable I resolves to 9
MLOGIC(TRIM): %IF condition %qsubstr(&value,&i,1) ne is TRUE
MLOGIC(TRIM): %GOTO TRIMMED (label resolves to TRIMMED).
SYMBOLGEN: Macro variable I resolves to 9
MLOGIC(TRIM): %IF condition &i>0 is TRUE
SYMBOLGEN: Macro variable VALUE resolves to EOD 12-27
SYMBOLGEN: Macro variable I resolves to 9
MLOGIC(TRIM): Ending execution.
SYMBOLGEN: Macro variable HLDDATE resolves to 'EOD 12-27'n
SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.
'EOD 12-27'n
SYMBOLGEN: Macro variable HLDDATE resolves to 'EOD 12-27'n
SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.
SYMBOLGEN: Macro variable DATADTE resolves to 'EOD 12-27'n
SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.
'EOD 12-27'n
SYMBOLGEN: Macro variable FILEDT resolves to 20201227
SYMBOLGEN: Macro variable PATH1 resolves to /users/emrmra/Dwight/Daily Monitoring and Escalation Report
SYMBOLGEN: Macro variable DATADTE2 resolves to 20201227
SYMBOLGEN: Macro variable HISDATA resolves to Cw3000
SYMBOLGEN: Macro variable DATADTE resolves to 'EOD 12-27'n
SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.
_
22
76
ERROR 22-322: Expecting a name.
ERROR 76-322: Syntax error, statement will be ignored.
SYMBOLGEN: Macro variable GRAPHTERM resolves to GOPTIONS NOACCESSIBLE;
150
Below code ran without errors.
options mlogic mprint merror nosource nonotes missing=0 symbolgen;
%put _automatic_;
libname Myfiles '/users/emrmra/Dwight/Daily Monitoring and Escalation Report';
%let path1=/users/emrmra/Dwight/Daily Monitoring and Escalation Report;
%let path2=/users/emrmra/Dwight/Daily Monitoring and Escalation Report;
/*******************************************************************************/
/*** Macro variables used for output file name and new column in file ***/
/*******************************************************************************/
%let filedt = 20201227;
%let HldDate='EOD 12-27'n;
%put &HldDate.;
%let DataDte=&HldDate;
%put &DataDte.;
%let DataDte2=&filedt;
%let hisdata=Cw3000;
/*******************************************************************************/
/*** Importing Inventory file from DMER ***/
/*******************************************************************************/
proc import out=dir
datafile="&path1/Daily Monitoring and Escalation Report_Enterprise.&DataDte2..xlsx"
dbms=xlsx replace;
getnames=yes;
range="Inventory$A2:&hisdata.";
run;
/*******************************************************************************/
/*** Filtering DMER Inventory for CCAR only ***/
/*******************************************************************************/
Data DetailData1;
set Dir;
if 'Used in CCAR'n = 'Y';
length EMRO $40.;
EMRO = 'Doe, John';
run;
/*******************************************************************************/
/*** Creating the different metrics (EMRO, MRO, MVL levels) ***/
/*******************************************************************************/
proc sql;
create table Program_Issues_EMRO1 as
select
'Enterprise' as Team
,'EMRO-HLS' as Role
,EMRO as Name
,'Active + Inactive Model Count' as Catageory
,count(*) as &DataDte
from DetailData1
Group by 1, 2, 3, 4;
quit;
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
INFO: Character variables have defaulted to a length of 200 at the places given by: (Line):(Column). Truncation can result.
40:1 RC
SYMBOLGEN: Macro variable _SASWSTEMP_ resolves to /home/nbddqv2/.sasstudio/.images/a46a955f-4b3f-4139-a6ae-f9da2c11f70c
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;
72
73 options mlogic mprint merror nosource nonotes missing=0 symbolgen;
AUTOMATIC AFDSID 0
AUTOMATIC AFDSNAME
AUTOMATIC AFLIB
AUTOMATIC AFSTR1
AUTOMATIC AFSTR2
AUTOMATIC FSPBDV
AUTOMATIC SYSADDRBITS 64
AUTOMATIC SYSBUFFR
AUTOMATIC SYSCC 0
AUTOMATIC SYSCHARWIDTH 1
AUTOMATIC SYSCMD
AUTOMATIC SYSDATASTEPPHASE
AUTOMATIC SYSDATE 28DEC20
AUTOMATIC SYSDATE9 28DEC2020
AUTOMATIC SYSDAY Monday
AUTOMATIC SYSDEVIC
AUTOMATIC SYSDMG 0
AUTOMATIC SYSDSN WORK PROGRAM_ISSUES_EMRO1
AUTOMATIC SYSENCODING latin1
AUTOMATIC SYSENDIAN LITTLE
AUTOMATIC SYSENV BACK
AUTOMATIC SYSERR 0
AUTOMATIC SYSERRORTEXT 76-322: Syntax error, statement will be ignored.
AUTOMATIC SYSFILRC 0
AUTOMATIC SYSHOSTINFOLONG Linux LIN X64 3.10.0-1160.2.2.el7.x86_64 #1 SMP Sat Oct 17 05:06:47 UTC 2020 x86_64 Red Hat Enterprise
Linux Server release 7.9 (Maipo)
AUTOMATIC SYSHOSTNAME lrdna455papdri
AUTOMATIC SYSINCLUDEFILEDEVICE
AUTOMATIC SYSINCLUDEFILEDIR
AUTOMATIC SYSINCLUDEFILEFILEREF
AUTOMATIC SYSINCLUDEFILENAME
AUTOMATIC SYSINDEX 18
AUTOMATIC SYSINFO 0
AUTOMATIC SYSJOBID 18312
AUTOMATIC SYSLAST WORK.PROGRAM_ISSUES_EMRO1
AUTOMATIC SYSLCKRC 0
AUTOMATIC SYSLIBRC 0
AUTOMATIC SYSLOGAPPLNAME
AUTOMATIC SYSMACRONAME
AUTOMATIC SYSMAXLONG 9007199254740992
AUTOMATIC SYSMENV S
AUTOMATIC SYSMSG
AUTOMATIC SYSNCPU 16
AUTOMATIC SYSNOBS 1811
AUTOMATIC SYSODSESCAPECHAR 03
AUTOMATIC SYSODSGRAPHICS 1
AUTOMATIC SYSODSPATH WORK.TEMPLAT(UPDATE) SASUSER.TEMPLAT(READ) SASHELP.TMPLMST(READ)
AUTOMATIC SYSPARM
AUTOMATIC SYSPRINTTOLOG
AUTOMATIC SYSPRINTTOLIST
AUTOMATIC SYSPROCESSID 41DCAE80A8785ACD4018000000000000
AUTOMATIC SYSPROCESSMODE SAS Workspace Server
AUTOMATIC SYSPROCESSNAME Object Server
AUTOMATIC SYSPROCNAME
AUTOMATIC SYSRC 0
AUTOMATIC SYSSCP LIN X64
AUTOMATIC SYSSCPL Linux
AUTOMATIC SYSSITE 70132342
AUTOMATIC SYSSIZEOFLONG 8
AUTOMATIC SYSSIZEOFPTR 8
AUTOMATIC SYSSIZEOFUNICODE 4
AUTOMATIC SYSSTARTID
AUTOMATIC SYSSTARTNAME
AUTOMATIC SYSTCPIPHOSTNAME lrdna455papdri.usrdnwx.amrs.bankofamerica.com
AUTOMATIC SYSTIME 16:43
AUTOMATIC SYSTIMEZONE GMT-05:00
AUTOMATIC SYSTIMEZONEIDENT ETC/GMT+5
AUTOMATIC SYSTIMEZONEOFFSET -18000
AUTOMATIC SYSUSERID nbddqv2
AUTOMATIC SYSVER 9.4
AUTOMATIC SYSVLONG 9.04.01M6P110718
AUTOMATIC SYSVLONG4 9.04.01M6P11072018
AUTOMATIC SYSWARNINGTEXT The data set WORK.DETAILDATA1 may be incomplete. When this step was stopped there were 0 observations and
2 variables.
SYMBOLGEN: Macro variable HLDDATE resolves to 'EOD 12-27'n
'EOD 12-27'n
SYMBOLGEN: Macro variable HLDDATE resolves to 'EOD 12-27'n
SYMBOLGEN: Macro variable DATADTE resolves to 'EOD 12-27'n
'EOD 12-27'n
SYMBOLGEN: Macro variable FILEDT resolves to 20201227
SYMBOLGEN: Macro variable PATH1 resolves to /users/emrmra/Dwight/Daily Monitoring and Escalation Report
SYMBOLGEN: Macro variable DATADTE2 resolves to 20201227
SYMBOLGEN: Macro variable HISDATA resolves to Cw3000
SYMBOLGEN: Macro variable DATADTE resolves to 'EOD 12-27'n
SYMBOLGEN: Macro variable GRAPHTERM resolves to GOPTIONS NOACCESSIBLE;
146
Hello,
Why don't you use valid SAS variable names ? You wouldn't have to deal with quoting problems.
If you can't changevariables names, you can try :
,count(*) as %unquote(&DataDte.)
How was DataDte generated ?
It sounds like you have a macro quoting problem. My guess is that the COLUMNDT variable was constructed something like
%let ColumnDt=%str(%'&someothervariable%'n);
The SAS processor cannot understand that quoted value as a name. I can replicate your error like this:
%let x=%str(%' x value%'n);
%put &x;
proc sql;
select name as &x from sashelp.class;
quit;
but when I use %unquote(&x) instead of &x (as suggested by @gamotte ), the program works OK.
If you are using the DataDte variable in many places, you may want to do the %unquoting there:
%let DataDte=%unquote(&ColumnDt);
and then leave the rest of your program unchanged.
Or you can do the unquoting on the original ColumnDt variable, if that makes for better code.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: