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

 

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
cau83
Pyrite | Level 9

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

2 REPLIES 2
cau83
Pyrite | Level 9

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;
ChrisNZ
Tourmaline | Level 20

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;

 

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 2 replies
  • 1845 views
  • 0 likes
  • 3 in conversation