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;
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;
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;
Thank you,
It works nicely.
HHC
@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.
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!
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.
Ready to level-up your skills? Choose your own adventure.