DATA Step, Macro, Functions and more

QSUBSTR out of range error

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

QSUBSTR out of range error

[ Edited ]

%if &file2 = I1099TY %then %do;
     %if &i = 2015 and &file2 = I1099TY and %qsubstr(&file3,1,5) = _2015  %then %do;
         %let pfile3 = _2016;
         %let sfile3 = %qsubstr(&file3,6,3);
         %let file3  = %trim(&pfile3&sfile3);

 

I get a warning stating that the %qsubstr is out of range. &file3 = _201706

 

EDIT: Note that @Reeza has modified the subject line to be reflective of the question. Please try and use a descriptive subject line in the future. 


Accepted Solutions
Solution
‎12-07-2017 03:02 PM
Super User
Posts: 6,541

Re: base sas

Posted in reply to mauri0623

Well, you don't exactly say what you want to achieve here.  If this gives you the right answer, it would be a possible solution:

 

%let sfile3 = %qsubstr(&file3,6,2);

View solution in original post


All Replies
Super User
Posts: 6,541

Re: base sas

Posted in reply to mauri0623

Yes, focus on this statement:

 

 %let sfile3 = %qsubstr(&file3,6,3);

 

When &FILE3 is _201706, the sixth character is the second "0".  If you start at that point, and attempt to take 3 characters, you will find that you run out of characters.  There are only two characters left.

Occasional Contributor
Posts: 9

Re: base sas

Posted in reply to mauri0623

Sorry &file3 - _201507

Occasional Contributor
Posts: 9

Re: base sas

Posted in reply to mauri0623

So what is the fixing solution?

Solution
‎12-07-2017 03:02 PM
Super User
Posts: 6,541

Re: base sas

Posted in reply to mauri0623

Well, you don't exactly say what you want to achieve here.  If this gives you the right answer, it would be a possible solution:

 

%let sfile3 = %qsubstr(&file3,6,2);

Occasional Contributor
Posts: 9

Re: base sas

Posted in reply to Astounding
Thank you much. This got rid of the warning.
PROC Star
Posts: 8,114

Re: base sas

Posted in reply to mauri0623

If you want everything from including and to the right of the sixth character just use

%qsubstr(&file3,6)

Art, CEO, AnalystFinder.com

 

☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 154 views
  • 1 like
  • 3 in conversation