DATA Step, Macro, Functions and more

Special SubStr character column

Reply
New Contributor
Posts: 3

Special SubStr character column

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. 

Trusted Advisor
Posts: 1,137

Re: Special SubStr character column

[ Edited ]

data want;
set have;

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

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

Thanks,
Jag
PROC Star
Posts: 325

Re: Special SubStr character column

something like this

compress(col,'','kad')
Trusted Advisor
Posts: 1,570

Re: Special SubStr character column

If it is always starting with capital A you can use

   

 var = substr(var, indexc(var,'A'));
New Contributor
Posts: 3

Re: Special SubStr character column

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

Trusted Advisor
Posts: 1,570

Re: Special SubStr character column

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.

PROC Star
Posts: 1,760

Re: Special SubStr character column

Keep everything starting at uppercase A:

data WANT;
 STR='+$A1234';
 STR1=prxchange('s/.*(A.*)/$1/',1,STR);
 putlog STR1=;
run;
Ask a Question
Discussion stats
  • 6 replies
  • 162 views
  • 5 likes
  • 5 in conversation