DATA Step, Macro, Functions and more

Header validation

Reply
Super Contributor
Posts: 647

Header validation

Problem Description:
We get montly data in excel files every month from various vendors.The data type of variables for each pharmacy is not consistent.I would like to define the data type for all the variables and I would like to check before the any analysis is done. How to achieve this.
Say for instance:
I want the patient_birth_year and zip to be numeric so that I can apply z5 format on zip later in my program. Some vendors give the zip in character and some give in numeric. I would like to check the variables at the very beginning.
PROC Star
Posts: 1,564

Re: Header validation

The proper way is to analyse the variable types one by one (using vtypex() or proc contents ) and fix the bad ones.
A faster way is to redefine them all in bulk and let sas do the translation, like:

[pre]
data clean_up;
length varc1 varc2 $8 varn1 varn2 8;
keep varc1 varc2 varn1 varn2 ;
set excel_import(keep=tempvarc1 tempvarc2 tempvarn1 tempvarn2);
varc1=tempvarc1;
varc2=tempvarc2;
varn1=tempvarn1;
varn2=tempvarn2;
run;
[/pre]
Depending on how much clean-up is required, the 2nd way might be sufficient.
Super Contributor
Super Contributor
Posts: 3,174

Re: Header validation

I would say that any variability permitted with input data is much like a crap-shoot.

The example with ZIPCODE is a good one - do you intend to truncate a ZIP+4 (character string) at the first 5 characters when submitted, just so you can treat the data as numeric? Why not take the data as the sender has intended and convert it properly to character, maintaining leading zero prefix substring for the certain zip codes?

If you intend to maintain job security by allowing uncontrolled input formats, so be it -- and SAS can handle the task, presuming the individual supporting the application can maintain the input/decoding SAS program(s) needed to ensure data quality along the way.

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 2 replies
  • 112 views
  • 0 likes
  • 3 in conversation