Saturday, April 1, 2017

How to Separate Address Values (SAS)

So you’re working with a data set, and one of the variable columns contains an address value structured such as:

303 SAS LANE, Cleveland, OH 1111

How would you format such data so that each part of the address has its own variable column? The following code will take care of it for you.

data DataSetB; /* New data set name */
    set DataSetA; /* Old data set name */
    Street = scan(Address, 1, ','); /* Creates a variable column for the street value */
    City = scan(Address, -3); /* Creates a variable column for the city variable */
    State = scan(Address, -2); /* Creates a variable column for the state variable */
    Zip = scan(Address, -1, ' '); /* Creates a variable column for the zip variable */
run;
 
The above code achieves its purpose through the utilization of the SCAN function. Below is a link that provides more information as to how the function can be successfully utilized.

SAS University Manual Topic: SCAN Function


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.