BookmarkSubscribeRSS Feed
King
Calcite | Level 5

data test;

first='ipswich,England';

city=substr(first,1,7);

cc=city!!','!!'England';

run;

op is giving spaces b/w ipswich and england. why?

2 REPLIES 2
ballardw
Super User

Basically because you haven't told it not to. CITY is created as 15 characters, the length of FIRST and treated as though that is the desired length.

Try either:

cc= strip(city)||','||'England';

or

cc= trim(left(city))||','||'England';

or

cc=cats(city, ',' , 'England');

or

cc=catx(',', city, 'England');

DF
Fluorite | Level 6 DF
Fluorite | Level 6

This article in the SAS Documention will help http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a001336069.htm .

Basically, the problem starts because you've not specified character lengths.  SAS then picks the length based on the first value is sees for each variable you've used.  "First" is set to 15, "City" copies this and is 15 too, while "CC" is set to 23 (i.e. 15 plus the length of ",England" (8) = 23).

To work for your example you should either set the character lengths, or explore using the "TRIM" function when appending character variables.  (Actually you'll probably end up using both.)

Hope that helps!

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
  • 730 views
  • 0 likes
  • 3 in conversation