BookmarkSubscribeRSS Feed
rawindar
Calcite | Level 5

name=j** ney

in the above data value there is a two * are there after J.Using compress we can remove this *.But i need to remove only 1 *.How can i write the code.

3 REPLIES 3
Hoz
Calcite | Level 5 Hoz
Calcite | Level 5

How about use "prxchange".

name="j** ney";

txt = prxchange('s/\*\*/*/',-1,name);

put txt=;

Best Regards,

Keith
Obsidian | Level 7

I agree with Hoz, prxchange is the way to do this.  A slight modification to Hoz's code will replace any number of consecutive * to a single *.

txt = prxchange('s/\*+/*/',-1,name);

Patrick
Opal | Level 21

Using a regular expression with prxchange() is for sure a very powerful way of modifying a string.

Considering that it's such a simple text pattern and the question is asked in the "Getting started" forum using a function like TRANSTRN() is also acceptable.

data _null_;

  myVariable='name=j** ney';

  myVariable=TRANSTRN(myVariable,'**','*');

  put myVariable=;

run;

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
  • 3 replies
  • 497 views
  • 0 likes
  • 4 in conversation