user10382630
user10382630

Reputation:

Splitting Strings in SAS

I have values in a variable that look like:

B1234
A0345
C65405

I want to split it so that it so that it will appear as the first 3 characters followed by everything else as shown below.

B1234: B12 34
A0345: A03 45
C65405: C65 405

Is there any way I can do this in SAS

Thanks!

Upvotes: 0

Views: 1127

Answers (3)

Richard
Richard

Reputation: 27498

Use a WHERE statement, or an IF statement

where item_code like 'B1%'

or

if item_code =: 'B1'

There are other ways but you haven't explained the situation in more detail

Upvotes: 0

Dmitry.Kolosov
Dmitry.Kolosov

Reputation: 635

I think the solution suggested by Stu with substr is the easiest, but you can also do it using regexes:

result = prxChange('s/^(.{3})(.*)/$1 $2/', -1, trim(source));

Upvotes: 1

Stu Sztukowski
Stu Sztukowski

Reputation: 12849

Use substr() and concatenate them.

data want;
    var = 'B1234';
    split = catx(' ', substr(var, 1, 3), substr(var, 4) );
run;

Upvotes: 2

Related Questions