SUPPORT / SAMPLES & SAS NOTES
 

Support

Sample 33027: Looking for Unique Codes in Your Data

DetailsCodeAboutRate It
Many of us are presented with SAS data sets where codes such as 9999 are intermingled with real data values. Sometimes these codes represent missing values; sometimes they represent other non-data values.

If you run SAS procedures on numeric variables in such a data set, you will, obviously, produce nonsense. What we present here is a macro that will automatically check all the numeric variables in a SAS data set for a specific data value, and produce a report showing which variables contain this special value and how many times it appeared.

The macro is called FIND_VALUE and is presented below. You can download this macro and many other useful macros from the SAS Companion Web Site: support.sas.com/publishing. Search for my book, Cody's Data Cleaning Techniques, Second Edition, and then click on the link to download the programs and data files from the book.

You call the macro like this:

%find_value(Dsn=the name of your SAS data set,
            Value=the value you are looking for)  

To demonstrate this macro, a data set called SPECIAL was created with several character and numeric variables. Values of 9999 were entered several times for some of the numeric variables. The macro call looks like this:

%find_value(Dsn=Special, Value=9999)

With the following result:

image label

This sample was authored by Ron Cody. His books:

are available from the SAS Publishing online bookstore.


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.