BookmarkSubscribeRSS Feed
amol2939
Calcite | Level 5
I have an
data have;
Input result $;
Data lines;
Abc
Def
Hjkkk
Lkhhhh
;
Run;
I want to remove the trailing blanks
And want to see in which observation the blank have been removed
4 REPLIES 4
Patrick
Opal | Level 21

SAS character variables are fixed length (type CHAR). If you just use $ without a length specification in your input statement then the variable will become character with a length of 8.

As it's fixed length there are always trailing blanks unless your string is already 8 characters.

 

So: Removing trailing blanks is not possible but if you just want to know how long your strings actually are then you can use the length() or lengthn() function.

data have;
  input result $;
  lenOfString=length(result);
  datalines;
Abc
Def
Hjkkk
Lkhhhh
;
proc print;
run;

 

JerryV
SAS Employee

Building upon Kurt's and Patrick's responses.  The below code shows what they have said.  Now you can compare lenOfString and columnLengthOf_result to see when strip() does something.

data have;
input result $;
retain columnLengthOf_result 0;
if _n_=1 then columnLengthOf_result=vlength(result);
lenOfString=length(result);
Original_result='(' || result || ')';
Stripped_result='(' || strip(result) ||')';

datalines;
Abc
Def
Hjkkk
Lkhhhh
;;;;

ballardw
Super User

Please describe what you are doing that "trailing blanks" is causing problems or affecting your analysis.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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