BookmarkSubscribeRSS Feed
venkatard
Calcite | Level 5

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.

5 REPLIES 5
allurai0412
Fluorite | Level 6

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

venkatard
Calcite | Level 5

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

UrvishShah
Fluorite | Level 6

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

Peter_C
Rhodochrosite | Level 12

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

Jagadishkatam
Amethyst | Level 16

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 861 views
  • 0 likes
  • 5 in conversation