DATA Step, Macro, Functions and more

dropping last observations

Accepted Solution Solved
Reply
Contributor
Posts: 69
Accepted Solution

dropping last observations

 

Hi,

 

I want to drop the last observations from my data set but want to keep them only if the date is 29dec2017. I am using the following code, although it works perfectly fine but I am just unsure how to incorporate the date clause in it. 

 

data want(drop=count);
  set have;
  by permno descending date;
  if first.permno then count=0;
  count+1;
  if count>1;
run;

 


Accepted Solutions
Solution
2 weeks ago
Frequent Contributor
Posts: 111

Re: dropping last observations

I added the code in CAPS below. Check the date first, then set count to zero if not that day.

data want(drop=count);
  set have;
  by permno descending date;
  IF DATE = "29DEC2017"d THEN COUNT=1;
  ELSE if first.permno then count=0;
  count+1;
  if count>1;
run;

View solution in original post


All Replies
Solution
2 weeks ago
Frequent Contributor
Posts: 111

Re: dropping last observations

I added the code in CAPS below. Check the date first, then set count to zero if not that day.

data want(drop=count);
  set have;
  by permno descending date;
  IF DATE = "29DEC2017"d THEN COUNT=1;
  ELSE if first.permno then count=0;
  count+1;
  if count>1;
run;
Super User
Posts: 2,516

Re: dropping last observations

Drop the last observation? How?

This:

data want(drop=count);
  set have;
  by permno descending date;
  if first.permno then count=0;
  count+1;
  if count>1;
run;

is the same is that:

data want;
  set have;
  by permno descending date;
  if first.permno then delete;
run;

 

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 75 views
  • 0 likes
  • 3 in conversation