AFHood Group Blog The thoughtless yammerings of marketing junkies..


The SAS Scan Function

Here is a useful function for you. The SCAN function. Scan allows you to isolate a word ( or group of letters ) in a text string given a definable set of delimiters. Here is an example.

data _null_;

string='Here is my string';

first_word=scan( string, 1, ' ' ); **First word in a string;

last_word=scan( string, -1, ' ' ); **Last word in a string;


Keep in mind that a word is simply defined as a group of letters between two delimiters. So you can scan strings using various tricks.

data _null_;

string='Hello SAS community people';

beginning= scan( string, 1, 'S' ); ** returns "Hello ";

middle = scan( string, 2, 'S' ); ** returns "A";

end= scan( string, 3, 'S' ); **returns " community people";


AFHood Analytics Group has consultants on staff to help with your SAS scripts. We can work with you on a small fix or a large development projects. Contact us to discuss how we can work together.

Comments (1) Trackbacks (0)
  1. Boa Postagem!!

    Grande Abra├žo.

Leave a comment

No trackbacks yet.