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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 19 replies
  • 1733 views
  • 8 likes
  • 5 in conversation