Help using Base SAS procedures

Trim variables in PROC SQL

Accepted Solution Solved
Reply
Contributor
Posts: 71
Accepted Solution

Trim variables in PROC SQL

[ Edited ]

Is there a function or statement that would trim blanks from an imported SQL character variable? e.g. similar to SAS functions STRIP or TRIM.

For example, if use the following code, STRIP has no impact but it doesn't give an error message either:

 

Proc sql; 

select strip(variable_name) as no_blanks

from xxxx_database;

quit;


Accepted Solutions
Solution
‎11-24-2016 04:24 PM
Super User
Posts: 17,868

Re: PROC SQL

So, if a character has a set length of 12 but you trim it, it still has a length of 12. Make sure you use, LENGTHN to check the length.

 

Also, it can be other invisible characters, you can use a hex format to view your data to check. I think 20 is a space and anything else is a different character.

 

put variable_name $hex.;

View solution in original post


All Replies
Super User
Posts: 17,868

Re: PROC SQL

Are these leading or trailing blanks? Are you sure they're blanks? 

What makes you think it hasn't worked? 

Contributor
Posts: 71

Re: PROC SQL

Thanks for your reply. Your question puzzled me now, I'm not sure they are blanks!,  although when I do proc print they look so.

I created a data set from the SQL statement and used the trim and strip functions in a data statement but looks like the character variables are still the same length with what it looks like a lot of trailing blanks.

 

I may have to investigate more...

Solution
‎11-24-2016 04:24 PM
Super User
Posts: 17,868

Re: PROC SQL

So, if a character has a set length of 12 but you trim it, it still has a length of 12. Make sure you use, LENGTHN to check the length.

 

Also, it can be other invisible characters, you can use a hex format to view your data to check. I think 20 is a space and anything else is a different character.

 

put variable_name $hex.;
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 456 views
  • 1 like
  • 2 in conversation