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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

3 REPLIES 3
Reeza
Super User

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

What makes you think it hasn't worked? 

PTD_SAS
Obsidian | Level 7

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...

Reeza
Super User

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.;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 3008 views
  • 1 like
  • 2 in conversation