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

Hello,

 

I am using call scan to substring a variable to remove the last number from the string. I am receiving the Note: Invalid error to substring, although it seems to be working.

 

Have:

 Capture.PNG

 

Want:

 

Capture.PNG

 

here is my code:

 

call scan(_egtpt, -1, pos, length) ;
egtpt= upcase(substr(_egtpt,1, pos-2));

 

LOG:

Capture.PNG

Any help with clearing the note would be appreciated. Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
None of your examples generate an error with either your code or novinsorin's. I suspect you have some blank _egptpt entries and those records may be throwing an error.

View solution in original post

7 REPLIES 7
Reeza
Super User
Can you post an example of the error with the log notes? That usually helps with determining what the issue is a lot quicker.
mglogan
Obsidian | Level 7
Yes! updated post with image
novinosrin
Tourmaline | Level 20

If your variable value has just 1 digit value as the last value, you don't need call scan

want=upcase(substr(k,1,length(k)-2));

 

 

novinosrin
Tourmaline | Level 20

Try

 

data w;
k='Pre-Dose 2';
/*call scan(k, -1, pos, length) ;*/
want=upcase(substr(k,1,length(k)-2));
run;
Reeza
Super User
None of your examples generate an error with either your code or novinsorin's. I suspect you have some blank _egptpt entries and those records may be throwing an error.
mglogan
Obsidian | Level 7

Thank you! there were a few missing values. Works great now!

ballardw
Super User

If you copy code and/or error messages directly from your log you can paste the text into a codebox opened using the forum's {I} icon. Then edit anything you don't want to show such as XXXX for sensitive data. I think this may be easier than creating an image file, editing the image and the pasting the image in the forum.

 

Then we can also highlight or otherwise indicate directly in the text where a problem may be.

hackathon24-white-horiz.png

Join the 2025 SAS Hackathon!

Calling all data scientists and open-source enthusiasts! Want to solve real problems that impact your company or the world? Register to hack by August 31st!

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
  • 7 replies
  • 1736 views
  • 5 likes
  • 4 in conversation