Help using Base SAS procedures

Must be a better way to do this (missing values)

Reply
Contributor
Posts: 29

Must be a better way to do this (missing values)

Hey all, I have an Access database that with a number of fields that use "-9999" as a "missing" value. I am going to read the data into SAS using Proc Import (I'm slightly scared of other methods) and then use a Data statement to translate the -9999 to the missing character.

This seems like a clunky way to do things, particularly with the sheer number of variables that are set up in this fashion. Is this the best way to do it, or is there another way (maybe ditch the Proc Import or streamline the Data statement)?

Thank you very much in advance for any help you can offer.
Super Contributor
Super Contributor
Posts: 3,174

Re: Must be a better way to do this (missing values)

Here is some DATA step code to consider using, an explicit array to address numeric variables only:

ARRAY a_num (*) _numeric_;
do i=1 to dim(a_num);
if = -999 then = .;
end;

Scott Barry
SBBWorks, Inc.
Contributor
Posts: 29

Re: Must be a better way to do this (missing values)

I see. Thank you very much for the reply.
PROC Star
Posts: 1,561

Re: Must be a better way to do this (missing values)

you can use Scott's code this way:

ARRAY a_num (*) _numeric_;
do i=1 to dim(a_num);
if a_num(i) = -9999 then a_num(i) = .;
end;

and all numeric variables are handled automatically without your having to name them.
Super User
Posts: 10,500

Re: Must be a better way to do this (missing values)

I would seriously look into creating one or more INFORMATS using Proc Format and INVALUE.

Something like this would set all values less than 0 to missing. The only issue is assigning the informat while using Proc Import. (Hint the log should contain a bunch of INFORMAT, FORMAT statements after the first run. Copy the code from the Log to the editor and apply as needed)

Proc format;
invalue groupval 0- high= _same_
other= .;
run;
Ask a Question
Discussion stats
  • 4 replies
  • 136 views
  • 0 likes
  • 4 in conversation