DATA Step, Macro, Functions and more

Using %qsubstr

Accepted Solution Solved
Reply
Super Contributor
Posts: 279
Accepted Solution

Using %qsubstr

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


Accepted Solutions
Solution
‎07-24-2017 09:16 AM
Super User
Super User
Posts: 7,942

Re: Using %qsubstr

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


All Replies
Solution
‎07-24-2017 09:16 AM
Super User
Super User
Posts: 7,942

Re: Using %qsubstr

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;
Super User
Posts: 7,762

Re: Using %qsubstr

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

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is solved.

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

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