Sample 24736: Scanning for words in a string
Using ARRAY processing and the SCAN function, pull out words from one string and store them in separate variables.
Note: See Create a separate macro variable for each 'word' in a string
for a macro technique using %QSCAN and a %DO %WHILE loop.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
/* Create three new variables by using an ARRAY statement, then 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
;
data two (drop=name i);
set one;
/* The LENGTH statement is used to give each variable a specific length. */
/* To give all the variables the same length, specify a length after the */
/* $ on the ARRAY statement. */
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;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
Obs first middle last
1 daniel john green
2 mary jane smith
3 kathy diane jones
Using ARRAY processing and the SCAN function, pull out words from one string and store them in separate variables.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step Data Management ==> Manipulation and Transformation ==> Array processing
|
| Date Modified: | 2007-04-30 03:02:49 |
| Date Created: | 2004-09-30 14:09:09 |
Operating System and Release Information
| SAS System | Base SAS | All | n/a | n/a |