BookmarkSubscribeRSS Feed
David_Billa
Rhodochrosite | Level 12

I'm not certain why I get the out of range warning after executing the code below. Am I missing something?

 

  data _null_;
 if symexist("_CD") then _CD = symget("_CD");
  else _CD = '';
  if symexist("ENTITY") then ENTITY = symget("ENTITY");
  else ENTITY = '';
 le=compress(COALESCEC(_CD,ENTITY));
call symput('le',le);
*drop _:;
run;

Log:

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
      
WARNING: Argument 3 to macro function %SUBSTR is out of range.
2 REPLIES 2
yabwon
Onyx | Level 15

Read the documentation:

Syntax

%SUBSTR(argument, position<, length>)
%QSUBSTR(argument, position<, length>)

Required Arguments

argument

is a character string or a text expression. If argument might contain a special character or mnemonic operator, listed below, use %QSUBSTR.

position

is an integer or an expression (text, logical, or arithmetic) that yields an integer, which specifies the position of the first character in the substring. If position is greater than the number of characters in the string, %SUBSTR and %QSUBSTR issue a warning message and return a null value. An automatic call to %EVAL causes n to be treated as a numeric value.

length

is an optional integer or an expression (text, logical, or arithmetic) that yields an integer that specifies the number of characters in the substring. If length is greater than the number of characters following position in argument, %SUBSTR and %QSUBSTR issue a warning message and return a substring containing the characters from position to the end of the string. By default, %SUBSTR and %QSUBSTR produce a string containing the characters from position to the end of the character string.


All the best

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Kurt_Bremser
Super User

Please COPY/PASTE (!!) the WHOLE log. Your code as posted does not contain ANY call of the %substr() macro function.

 


@David_Billa wrote:

I'm not certain why I get the out of range warning after executing the code below. Am I missing something?

 

  data _null_;
 if symexist("_CD") then _CD = symget("_CD");
  else _CD = '';
  if symexist("ENTITY") then ENTITY = symget("ENTITY");
  else ENTITY = '';
 le=compress(COALESCEC(_CD,ENTITY));
call symput('le',le);
*drop _:;
run;

Log:

NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
      
WARNING: Argument 3 to macro function %SUBSTR is out of range.

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2349 views
  • 0 likes
  • 3 in conversation