BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hhchenfx
Rhodochrosite | Level 12

Hi Everyone,

My data have few first rows with missing data. How can I delete them?

There are other missing but inside the good data and I need to keep those missing.

In the data below, I want to delete row row 1 and 2.

 

Thank you,

HHC

data have; 
input n v1;
datalines;
1 . 
2 . 
3 4 
4 66
5 .
6 66
7 3
8 .
9 8
;run;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

One option

data want(drop=_:);
  set have;
  retain _del_flg 1;
  if _del_flg then 
    do;
      _del_flg=missing(v1);
      if _del_flg then delete;
    end;
run;

View solution in original post

3 REPLIES 3
Patrick
Opal | Level 21

One option

data want(drop=_:);
  set have;
  retain _del_flg 1;
  if _del_flg then 
    do;
      _del_flg=missing(v1);
      if _del_flg then delete;
    end;
run;
hhchenfx
Rhodochrosite | Level 12

Thank you,

It works nicely.

HHC

ballardw
Super User

@hhchenfx wrote:

Hi Everyone,

My data have few first rows with missing data. How can I delete them?

There are other missing but inside the good data and I need to keep those missing.

In the data below, I want to delete row row 1 and 2.

 

Thank you,

HHC

data have; 
input n v1;
datalines;
1 . 
2 . 
3 4 
4 66
5 .
6 66
7 3
8 .
9 8
;run;

 


I suggest that perhaps you want to look at how you READ that data into SAS. Especially if you are reading multiple files and keep having these missing rows appear and the number is the same.

If you already know the number of missing rows, such as 2

data want;
   set have (firstobs=3);
run;

The firstobs option says to keep the observations starting with the 3rd one.

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 901 views
  • 0 likes
  • 3 in conversation