1.

What do you mean by the Scan function in SAS and write its usage?

Answer»

The SCAN() function is typically used to extract words from a value marked by delimiters (characters or special signs that separate words in a TEXT string). The SCAN function selects individual words from text or variables containing text and stores them in new variables. 

SYNTAX

scan(argument,n,delimiters)

In this case, 

  • Argument: It specifies the character variable or text to be scanned.
  • N: The number n indicates which word to read.
  • Delimiters: These are characters values or special signs in a text string.

Example:  

Consider that we would like to extract the first word from a sentence 'Hello, Welcome to Scaler!'. In this case, the delimiter used is a blank. 

data _null_; string="Hello, Welcome to Scaler!"; first_word=scan(string, 1, ' ' ); put first_word =; run;

First_word returns the word 'hello' SINCE it's the first word in the above sentence. Now, consider that we would like to extract the last word from a sentence 'Hello, Welcome to Scaler!'. In this case, the delimiter used is a blank. 

data _null_; string="Hello, Welcome to Scaler!"; last_word=scan(string, -1, ' ' ); put last_word =; run;

Last_word returns 'Scaler!' As Scaler is the last word in the above sentence.  



Discussion

No Comment Found