BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

Dear,

 

In my data, I need remove some characters from a variable (test) values. With my code I am not getting output I need for ONE observation.

Please look at OBS 4 (test=EXCL08C). i AM NOT GETTING THE OUTPUT I NEED FOR THIS.

Please help.

 

data

test

EXCL01

EXCL07B

EXCL08

EXCL08C

EXCL10

 

MY CODE;

if test =:'EXCL0' THEN TEST1=COMPRESS(TEST,'XCL0','');
ELSE IF test ^=:'EXCL0' THEN TEST1=COMPRESS(TEST,'XCL','');

 

RESULT;

E1

E7B

E8

E8

E10

 

OUTPUT NEED;

E1

E7B

E8

E8C

E10

 

 

3 REPLIES 3
Reeza
Super User

You may be better off using a SUBSTR() function?

 

Looks like you're taking first character and then everything after the 4th?

 

 

ballardw
Super User

I'm not sure this will easily extend if needed but works for the example data;

data example;
   informat test $10.;
   input test;
   result = tranwrd(test,'EXCL0','E');
   result = tranwrd(Result,'EXCL','E');
datalines;
EXCL01
EXCL07B
EXCL08
EXCL08C
EXCL10
;
Ksharp
Super User

data example;
   informat test $10.;
   input test;
   result = prxchange('s/XCL0*//i',-1,test);
datalines;
EXCL01
EXCL07B
EXCL08
EXCL08C
EXCL10
;
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
  • 9205 views
  • 4 likes
  • 4 in conversation