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
Onyx | Level 15

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
Onyx | Level 15

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



SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 3753 views
  • 8 likes
  • 5 in conversation