Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

while still missing data

Status
Not open for further replies.

deanj2k1

Programmer
May 28, 2009
5
GB
I have a program that replaces missing data and watn it to repeat unitl there are no more missing values. How would i got about doing this. So far i have, which does not work:

data Subjects;
nmiss=NMISS(wheezecomp);
%let missvaluesw=NMISS(wheezecomp);
%let missvaluesc=NMISS(coughcomp);
run;

do while (&missvaluesw ~= 0 AND &missvaluesc ~= 0);

... more code filling in missing data for wheezecomp and coughcomp...

data Subjects;
set Subjects;
%let missvaluesw=NMISS(wheezecomp);
%let missvaluesc=NMISS(coughcomp);
run;

end;
 
I don't understand. Is this 'wheezecomp' variable missing data? (Like if its a numeric variable is set to '.' or if its char variable set to blank?)

Do you have a value that you would like to substitute into the missing portion?

Code:
data Subjects;
***IF wheezecomp IS NUMERIC ***;
if wheezecomp = . then
   wheezecomp = 1; *** OR YOUR VALUE ***;

***IF wheezecomp IS CHAR ***;
if TRIM(wheezecomp) = '' then
   wheezecomp = '1'; *** OR YOUR VALUE ***;
run;

Hope this helps you.

Klaz
 
thanks for the input i was asking more along the lines of how to make my code loop until it fills in the missing values(how it fills the missing values is irrelevant). and to answer your question wheezecomp and coughcomp are both binary variables (0,1 or '.' for missing data).

I know the code shown above as '... more code filling in missing data for wheezecomp and coughcomp...' works as ive tested it by repeating manually.

i appreciate the help though!
 
ps: feel free to make suggestions which may be completely different to my code shown in my initial post.
 
How you fill the missing values I think is key to how to write your 'loop'. Perhaps I don't understand the data structure.

Perhaps you can post the data to this board and I can 'see' what you are trying to do. I don't care how you fill the missing data the only reason I asked the question was to see how your data was structured. When I know how its structured perhaps I can give some ideas on how to proceed.

Is your data saved across several data sets?

let me know.

Klaz
 
yes course. im starting to realise as a new SAS user that the programming language is set out completely different to other statistical packages im experienced in!

Perhaps i should explain what it does. I expect missing values to come in 'episodes' (ie a series of missing values) for cough and wheeze variables in time order (age).

*the code sorts in order of age (ascending) then creates a lag variable
*creates another lag variable by sorting age in descending order
*replaces '.' in wheezecomp and coughcomp if it is at the end or start of the episode by one of the lag variables (ie the previous/subsequent wheezecomp and coughcomp value)
*updates the lag variables and repeats til the code fills in

essentially it fills in the missing data like so:
000....111 > 0000011111
111....000 > 1111100000
000....000 > 0000000000
111....111 > 1111111111

^this particular example would take 2 iterations to fill in

note: when i refer to wheezecomp and coughcomp I am just talking about two similar binary variables with missing values. for solutions please feel free to give a solution to one

***************code:

/*** This section deals with missing data and replaces it with ***/
/*** logical predicted values.***/

/* Creates a separate variable for wheeze and cough which will eventually have no */
/* missing data */

data Subjects;
set Subjects;
wheezecomp=wheeze;
coughcomp=cough;
run;

/* Fills in the missing data with the previous (1) wheeze or (2) cough then */
/* re-sorts the data in descending order of age to fill in the missing data */
/* with the next non-missing (1) wheeze or (2) cough... */
/* this process repeats until there is no more missing data to replace */


data Subjects;
set Subjects;
nmiss=NMISS(wheezecomp);
%let missvaluesw=NMISS(wheezecomp);
%let missvaluesc=NMISS(coughcomp);
run;

do while (&missvaluesw ~= 0 AND &missvaluesc ~= 0);

proc sort data=Subjects out=Subjects;
by id age;
run;

data Subjects;
set Subjects;
advwheeze=lag(wheezecomp);
advcough=lag(coughcomp);
run;

proc sort data=Subjects out=Subjects;
by id descending age;
run;

data Subjects;
set Subjects;
lagwheeze=lag(wheezecomp);
lagcough=lag(coughcomp);
run;

proc sort data=Subjects out=Subjects;
by id age;
run;

data Subjects;
set Subjects;
if wheezecomp=. then wheezecomp=advwheeze;
if coughcomp=. then coughcomp=advcough;
run;

proc sort data=Subjects out=Subjects;
by id descending age;
run;

data Subjects;
set Subjects;
if wheezecomp=. then wheezecomp=lagwheeze;
if coughcomp=. then coughcomp=lagcough;
run;

data Subjects;
set Subjects;
%let missvaluesw=NMISS(wheezecomp);
%let missvaluesc=NMISS(coughcomp);
run;

end;
 
One thing that you have to understand is that MACRO vars get resolved before runtime. Its SAS's way of compiling the code twice. This stated, you now have a function NMISS that never gets called. Perhaps you have to rethink the logic on how to fill in missings.

Klaz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top