Help using Base SAS procedures

delete leading missing values

Reply
Super Contributor
Posts: 399

delete leading missing values

Hi, is there a way to delete leading missing values from a dataset, with by groupings.  So I have a large dataset by postal codes and car prices, and car models.  certain car models werent built until certain years while others go way back.. I don't want to delete all missing since I need the missing values in between that I just don't have any prices for.  Just the leading missing whenever they had happend for each model.  thanks

PROC Star
Posts: 7,416

delete leading missing values

Can you provide an example of what your records currently look like and how you want them to look after being manipulated?

Super Contributor
Posts: 399

delete leading missing values

Hi Art,

I just realized that if I wanted to keep all variables in the same dataset, then the oldest value is the one that belongs to the first non-missing date. All the others that are also in the dataset will have a missing value (if they don't have any data) starting from that same date.

Super User
Posts: 5,222

Re: delete leading missing values

podarum,

It sounds like this is what you are trying to do.

proc sort data=my_data;

   by postal_code car_model time_period;

run;

data remove_missings;

   set my_data;

   by postal_code car_model;

   retain keep_deleting;

   if first.car_model then keep_deleting='Y';

   if car_price=. then do;

      if keep_deleting='Y' then delete;

   end;

   else keep_deleting='N';

   drop keep_deleting;

run;

I'm not sure if you need postal_code in the logic or not ... depends on what you are trying to accomplish.

Good luck.

SAS Employee
Posts: 416

delete leading missing values

Hello -

I might be wrong, but this question seems to be related to your post: http://communities.sas.com/message/114872#114872

Again I believe that PROC TIMESERIES (of SAS/ETS) could be of interest, since the start date variable in the OUTSUM data set tells you when the first nonmissing observation per BY group occurred.

Then it should be easy to delete these observations from your original data set.

Hope this makes sense.

Regards,

Udo

Ask a Question
Discussion stats
  • 4 replies
  • 201 views
  • 0 likes
  • 4 in conversation