BookmarkSubscribeRSS Feed
Reeza
Super User
It does, you should only see 20 after the string in the variable value4. SAS always add extra spaces to pad out to the length of the variable from your example.
Reeza
Super User
It doesn't remove every single special character - you need to explicitly list the ones you want removed. From your sample data it's the two shown.

yabwon
Amethyst | Level 16

If you want to delete leading and trailing spaces('20'x) and "enters" (LF, CR) you could try to "resolve" it his way

 

data test;
  x='0A20200D55722055720D0A6F6C6F67790D0A20200D0A0D0A0D0A0D0A'x;
  put "*" x= char. +(-1)'*';
  put "*" x= hex. +(-1)'*';

  s=FINDC(x,, 1,'KS'); /* first "non space" */
  e=FINDC(x,,-vlength(x),'KS'); /* last "non space" */
  put s= e=;

  x=substr(x,s,e-s);
  put "*" x= char. +(-1)'*';
  put "*" x= hex. +(-1)'*';
run;

 

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



David_Billa
Rhodochrosite | Level 12

@yabwon I want to delete CR, LF and Spaces or any special characters before and after the string. Then how to tweak your code?

yabwon
Amethyst | Level 16

Define "special characters" ? 

 

The answer will probably be: change FINDC() functions modifiers.

Basically "SK" means "search for first character that is NOT a space, a horizontal tab, a vertical tab, a carriage return, a line feed, and a form feed". 

Probably you would like to add "C" for control characters, so in total "SCK".

 

Or maybe just make it: "ANP" to search for first  alphabetic character, punctuation mark, or digits, an underscore, and English letter?

 

Bart

 

P.S. are you using two accounts: @David_Billa and @Babloo ?

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 19 replies
  • 6148 views
  • 8 likes
  • 5 in conversation