Sample 24851: Using a Colon Modifier to Select Observations with Values Beginning with a Specific Character By Kirk Paul Lafler
If you need a quick way to subset observations that begin with a specific character, consider using a colon (:) modifier. By using a colon (:) modifier after a comparison operator in a DATA step, you can easily compare a specific prefix to a character string. This approach makes it easy to perform comparisons by truncating the longer value to the length of the shorter value. The following example compares the first position of the RATING variable to the character string 'P' to determine whether to subset an observation.
DATA MOVIES;
INFILE CARDS DSD;
INPUT TITLE :$11. RATING $;
IF RATING =: 'P';
CARDS;
Brave Heart,R
Jaws,PG
Rocky,PG
Titanic,PG-13
;
RUN;
PROC PRINT NOOBS N;
RUN;
|
Results
TITLE RATING
Jaws PG
Rocky PG
Titanic PG-13
N = 3
About the Author
Kirk Paul Lafler is a SAS Alliance Partner and SAS Certified Professional with 25 years of SAS software experience. He has written three books and over one hundred peer-reviewed articles for professional journals and SAS User Group proceedings. His popular SAS Tips column appears regularly in the SANDS and SESUG Newsletters. His expertise includes application design and development, training, and programming using base SAS, SQL, ODS, SAS/FSP, SAS/AF, SCL, FRAME, and SAS/EIS software.
If you would like more information or have any questions about this tip, please contact Kirk Lafler, Software Intelligence Corporation at KirkLafler@cs.com. Kirk's new book, Power SAS: A Survival Guide is published by Apress and provides SAS users with the largest and most comprehensive collection of SAS tips and techniques ever offered. Power SAS can be purchased on Amazon.com, BarnesandNoble.com and other online retailers, as well as your favorite Borders and Barnes & Noble bookstores.
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.
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.
Using the colon modified to subset observations that begin with a specific character.
Type: | Sample |
Topic: | Non SAS Authors ==> Kirk Paul Lafler
|
Date Modified: | 2005-02-03 08:47:43 |
Date Created: | 2004-11-09 07:44:29 |
Operating System and Release Information
SAS System | Base SAS | All | n/a | n/a |