BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mauri0623
Quartz | Level 8

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

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

6 REPLIES 6
Astounding
PROC Star

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.

mauri0623
Quartz | Level 8

Sorry &file3 - _201507

mauri0623
Quartz | Level 8

So what is the fixing solution?

Astounding
PROC Star

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);

mauri0623
Quartz | Level 8
Thank you much. This got rid of the warning.
art297
Opal | Level 21

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

%qsubstr(&file3,6)

Art, CEO, AnalystFinder.com

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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