## Hi., I m beginner of Sas base so help me out

Solved
Occasional Contributor
Posts: 13

# Hi., I m beginner of Sas base so help me out

Data Sample;

input var \$20.;

datalines;

car123personal

truck456commercial

bike789racing

;

run;

I need to place this argument into three variables and output as

Vehicle   Number  Purpose

car          123        personal

truck        456       commercial

bike         789       racing

Accepted Solutions
Solution
‎08-02-2013 03:31 AM
Frequent Contributor
Posts: 88

## Re: Hi., I m beginner of Sas base so help me out

PRX functions to the rescue.

Try this...

Data Sample;

input var \$20.;

length var2 \$25;

var2 = prxchange('s/([a-z]+)(\d+)([a-z]+)/\$1 \$2 \$3/',-1,var);

vehicle = scan(var2,1);   number = input(scan(var2,2),3.);

purpose = scan(var2,3);

datalines;

car123personal

truck456commercial

bike789racing ;

run;

The prxchange function is being used here to insert delimiters between the elements of the data, which the SCAN function can easily chop up.

You will need to read the documentation to see just how the PRXCHANGE function works!!

All Replies
Frequent Contributor
Posts: 80

## Re: Hi., I m beginner of Sas base so help me out

i there any delimiter ???

Occasional Contributor
Posts: 13

## Re: Hi., I m beginner of Sas base so help me out

nope.. no delimeter to separate itz complete single character argument. we need to split it into 3 variables

Solution
‎08-02-2013 03:31 AM
Frequent Contributor
Posts: 88

## Re: Hi., I m beginner of Sas base so help me out

PRX functions to the rescue.

Try this...

Data Sample;

input var \$20.;

length var2 \$25;

var2 = prxchange('s/([a-z]+)(\d+)([a-z]+)/\$1 \$2 \$3/',-1,var);

vehicle = scan(var2,1);   number = input(scan(var2,2),3.);

purpose = scan(var2,3);

datalines;

car123personal

truck456commercial

bike789racing ;

run;

The prxchange function is being used here to insert delimiters between the elements of the data, which the SCAN function can easily chop up.

You will need to read the documentation to see just how the PRXCHANGE function works!!

Occasional Contributor
Posts: 13

## Re: Hi., I m beginner of Sas base so help me out

Thanks a lot JerryLeBreton........ Itz working

Super Contributor
Posts: 644

## Re: Hi., I m beginner of Sas base so help me out

Here is a solution that does not use PRX functions and is perhaps easier to understand and maintain:

Use the numbers to act as a delimiter between the first and third variables

vehicle = scan (var, 1, '1234567890') ;

purpose = scan (var, 3, '1234567890') ;

Then throw away the non numeric characters

number = compress (var,,'KD') ;

Richard

🔒 This topic is solved and locked.