DATA Step, Macro, Functions and more

Missing data deletion in observations - Any help

Reply
Contributor
Posts: 63

Missing data deletion in observations - Any help

How can i delete the missing observations.

Ex:

user   class   score

1          123     90

2          143     89

3          143     12

4            .        .

5            .        .

i do not want observation 4 and 5 as the variables are missing.

Frequent Contributor
Posts: 97

Re: Missing data deletion in observations - Any help

Posted in reply to venkatard

hi try this,

data exp1;

input user class score ;

if missing(class) and missing(score) then delete;

datalines;

1 123 90

2 143 89

3 143 12

4 . .

5 . .

;

run;

Regards

ALLU

Contributor
Posts: 63

Re: Missing data deletion in observations - Any help

Posted in reply to allurai0412

I want to take 80 percent of total unique id as seperate dataset and the other 20 percent as seperate.

Regular Contributor
Posts: 195

Re: Missing data deletion in observations - Any help

Posted in reply to venkatard

Hi,

Try the following SAS Code...

/*Remove the duplicates from IDs*/

proc sort nodupkey data = test;

     by id;

run;

/*Calculating Percentage*/

data _null;

   set test end = eof;

   if eof then do;

      totobs = _n_;

      percent = round((80*totobs)/100);

      call symput('_80_percent',percent);

   end;

run;

/*Separating IDs based on Percentges*/

data data_80 data_20;

   set test;

   if _n_ LE &_80_percent. then output data_80;

   else output data_20;

run;

Hope it meets the requirement and please confirm that you split the IDs on the basis of PERCENTAGE not the PERCENTILE...If it is the later then this code wont work...

Thanks,

Urvish

Valued Guide
Posts: 2,177

Re: Missing data deletion in observations - Any help

Posted in reply to venkatard

Should the 80/20 split all non-missing rows, or be based on distinct ID (with non-missing data)  ?

assuming an ID might appear more than once

Is the selection supposed to be random 20%

peterC

Trusted Advisor
Posts: 1,137

Re: Missing data deletion in observations - Any help

Posted in reply to venkatard

hi,

You can use arrays as well to delete the missing observations.

data have;

  input user class score;

cards;

1          123     90

2          143     89

3          143     12

4            .        .

5            .        .

;

run;

data want;

  set have;

  array mis(*) _numeric_;

  do i=1 to dim(mis);

  if mis(i)=. then delete;

  end;

run;

Thanks,

Jagadish

Thanks,
Jag
Ask a Question
Discussion stats
  • 5 replies
  • 240 views
  • 0 likes
  • 5 in conversation