BookmarkSubscribeRSS Feed
ileshem
Calcite | Level 5

Hello,

 

I want to take a column withe expresions like:

 

column1

+$A1234

A4567

+#A7890

A9876

 

and creat a new colmun that will give me only the expression startin with "A" and the number after it"

 

column1

A1234

A4567

A7890

A9876

 

I tried to us a formula substr starting with "A": 

 

Substr(:colmun1, A, 5)

 

Any help will be appreciated. 

6 REPLIES 6
Jagadishkatam
Amethyst | Level 16

data want;
set have;

id=prxparse('/\w\d+/');

call prxsubstr(id,column1,start,length);
column2=substr(column1,start,length);
run;

Thanks,
Jag
kiranv_
Rhodochrosite | Level 12

something like this

compress(col,'','kad')
Shmuel
Garnet | Level 18

If it is always starting with capital A you can use

   

 var = substr(var, indexc(var,'A'));
ileshem
Calcite | Level 5

Thanks, what is "var" and indexc should be only index, right?

Shmuel
Garnet | Level 18

replace var with any variable name.

indexc function looks for a character (or characters) while index function looks for a string.

in this case as the list is made of one character, you can use each of the functions.

ChrisNZ
Tourmaline | Level 20

Keep everything starting at uppercase A:

data WANT;
 STR='+$A1234';
 STR1=prxchange('s/.*(A.*)/$1/',1,STR);
 putlog STR1=;
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
  • 6 replies
  • 876 views
  • 5 likes
  • 5 in conversation