www.sas.com > Service and Support > Technical Support
 
Technical Support SAS - The power to know(tm)
  TS Home | Intro to Services | News and Info | Contact TS | Site Map | FAQ | Feedback

/****************************************************************/
/* Title: Scanning for words in a string                        */
/*                                                              */
/* Goal: Using ARRAY processing, pull out words from one string */
/*       and store them in separate variables.                  */
/*                                                              */ 
/****************************************************************/

/* Create three new variables by using an ARRAY statement, and use 
   the SCAN function to pull the names out of the string and store them    
   in the new variables.					  
*/

/* Create a sample data set */

data one;
  input name $30.;
datalines;
daniel john green
mary jane smith
kathy diane jones
;
run;


data two (drop=name i);
  set one;

/* The LENGTH statement is used to give each variable a specific length;
   however, one length could be used after the $ on the ARRAY statement
   to give all of the array variables the same length. 
*/

  length first $10. middle $10. last $12.;
  array names(3) $ first middle last;
  do i= 1 to 3;
    names(i)=scan(name,i,' ');
  end;
run;

proc print;
run;

/* RESULTS  */

Obs    first     middle    last

 1     daniel    john      green
 2     mary      jane      smith
 3     kathy     diane     jones




Copyright (c) 2003 SAS Institute Inc. All Rights Reserved.
Terms of Use & Legal Information | Privacy Statement