DATA Step, Macro, Functions and more

Invalid third argument to function SUBSTR

Accepted Solution Solved
Reply
Regular Contributor
Posts: 194
Accepted Solution

Invalid third argument to function SUBSTR

Hello,

I'm getting teh folloiwng error: Invalid third argument to function SUBSTR

The variable cdcode is text and 14 characters long.

Here's my code:


data new;

     set old;

     length co $2 dist $5 sch $7;

     co=substr(cdcode, 1,2);

     dist=substr(cdcode, 3,7);

     sch=substr(cdcode,8,14);

run;

Can you help me understand why I'm getting this message?

Thanks!


Accepted Solutions
Solution
‎03-07-2013 01:00 PM
Trusted Advisor
Posts: 2,116

Re: Invalid third argument to function SUBSTR

RTFM.  Your code should read

sch=substr(cdcode,8,7);

View solution in original post


All Replies
Solution
‎03-07-2013 01:00 PM
Trusted Advisor
Posts: 2,116

Re: Invalid third argument to function SUBSTR

RTFM.  Your code should read

sch=substr(cdcode,8,7);
Regular Contributor
Posts: 194

Re: Invalid third argument to function SUBSTR

Thank you!  Is it because it's the last part of the cdcode that it's 7 instead of 14? 

Trusted Advisor
Posts: 2,116

Re: Invalid third argument to function SUBSTR

from the reference manual

"Interaction:If length is zero, a negative value, or larger than the length of the expression that remains in string after position, SAS extracts the remainder of the expression. SAS also sets _ERROR_ to 1 and prints a note to the log indicating that the length argument is invalid."

Regular Contributor
Posts: 194

Re: Invalid third argument to function SUBSTR

Thank you!!

🔒 This topic is solved and locked.

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

Discussion stats
  • 4 replies
  • 4293 views
  • 4 likes
  • 2 in conversation