SAS appears to resolve the macro variable ­r. The error occurs in the DATA step when I attempt to create a permanent data set.
My code:
options SYMBOLGEN;
%let yr=2017;
%let shyr=%qsubstr(&yr,3,2);
%put ­r;
***** LIBNAME *****;
libname eocep "G:\Departments\Research\test scores\EndOfCourse\&yr.";
data one;
..
run; /*the data step is error-free*/
*CREATE RAW PERM DATA SET*;
data eocep.eocep_spr­r._raw;
set one;
run;
LOG:
177 *CREATE RAW PERM DATA SET*;
SYMBOLGEN: Macro variable SHYR resolves to 17
SYMBOLGEN: Some characters in the above value which were subject to macro quoting have been unquoted for printing.
178 data eocep.eocep_spr­r._raw;
NOTE: Line generated by the macro variable "SHYR".
1 eocep.eocep_spr17_raw
--
22
--
200
ERROR 22-322: Syntax error, expecting one of the following: a name,
a quoted string, (, /, ;, _DATA_, _LAST_, _NULL_.
ERROR 200-322: The symbol is not recognized and will be ignored.
179 set one;
180 run;
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set EOCEP.EOCEP_SPR may be incomplete. When this step
was stopped there were 0 observations and 142 variables.
WARNING: Data set EOCEP.EOCEP_SPR was not replaced because this step was
stopped.
WARNING: The data set WORK._RAW may be incomplete. When this step was
stopped there were 0 observations and 142 variables.
WARNING: Data set WORK._RAW was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.09 seconds
cpu time 0.01 seconds
Use %substr rather than %qsubstr as qsubstr is masking some part of the string which is causing the issue later on. Can't think off the top of my head why as I never ever get into a situation where using these types of constucts is necessary, i.e. its never a good idea to put data into dataset names (those things used for programming).
options SYMBOLGEN; %let yr=2017; %let shyr=%substr(&yr,3,2); %put ­r; data eocep_spr­r._raw;; set sashelp.class; run;
Use %substr rather than %qsubstr as qsubstr is masking some part of the string which is causing the issue later on. Can't think off the top of my head why as I never ever get into a situation where using these types of constucts is necessary, i.e. its never a good idea to put data into dataset names (those things used for programming).
options SYMBOLGEN; %let yr=2017; %let shyr=%substr(&yr,3,2); %put ­r; data eocep_spr­r._raw;; set sashelp.class; run;
%qsubstr adds an internal token that informs the macro engine that macro triggers must not be resolved. That invisible token causes your problems.
Use %substr instead.
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 25. 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.