BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I am trying to use the following code where Region1 is a string variable


RegLen = length(Region1);

if substr(Region1,RegLen-7,8) = "Division" then
Region2 = cat(Region1," Support");

For some reason this won't work and the error occures at 'RegLen-7' in the substr function. when I replace this with a number, 14 for example' it works, but as Region1 can be any number of characters long I need this calculation in there.


Thanks
2 REPLIES 2
deleted_user
Not applicable
It works ok here:

data test ;
Region1='TEST Division' ;
RegLen = length(Region1) ;

if substr(Region1,RegLen-7,8) = "Division" then
Region2 = cat(Region1," Support") ;
run ;


Contents of dataset test:

Region1 RegLen Region2
TEST Division 13 Test Division Support
deleted_user
Not applicable
Worked out what the problem is now.

Some of the values for Region1 are less than 7 characters long and this is where was falling down.

Simple error, bit took hours to work out!!!!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 580 views
  • 0 likes
  • 1 in conversation