Splitting a string variable into two variables if a letter is present

Reply
Occasional Contributor
Posts: 7

Splitting a string variable into two variables if a letter is present

I have a string variable that contains numeric values and alphanumeric values. For instance:

var1

123

B23

3244

V190

 

I want:

var1  var2

123   .

.         B23

3244 .

.         V190

 

is there anyway to do this in SAS?

 

 

Regular Contributor
Posts: 236

Re: Splitting a string variable into two variables if a letter is present

Posted in reply to MikeBurton

something like this? 

data have;
input var1 $ @@;
datalines;
123 B23 3244 V190
;
run;
data want; 
	set have;
	if anyalpha(var1)>0 then do; var2=var1; call missing(var1); end;
run;
proc print data=want noobs; run;

Occasional Contributor
Posts: 7

Re: Splitting a string variable into two variables if a letter is present

Thanks Wong,

This code worked for what I wanted.

 

Respected Advisor
Posts: 4,278

Re: Splitting a string variable into two variables if a letter is present

Posted in reply to MikeBurton

@MikeBurton

Then please mark the question as answered.

PROC Star
Posts: 1,071

Re: Splitting a string variable into two variables if a letter is present

Posted in reply to MikeBurton

Is the letter always the first character of the string?

Ask a Question
Discussion stats
  • 4 replies
  • 102 views
  • 1 like
  • 4 in conversation