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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 749 views
  • 0 likes
  • 3 in conversation