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

SAS appears to resolve the macro variable &shyr. 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 &shyr;

***** 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&shyr._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&shyr._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

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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 &shyr;
data eocep_spr&shyr._raw;;
set sashelp.class;
run;

View solution in original post

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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 &shyr;
data eocep_spr&shyr._raw;;
set sashelp.class;
run;
Kurt_Bremser
Super User

%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.

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
  • 2 replies
  • 1242 views
  • 0 likes
  • 3 in conversation