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

For this I have already looked at the posts in the community, but they seemed to not serve my purpose. I tried the following code, which did not work.

data zzz; 
set yyy;
by return notsorted;
if Day= "Sun" and first.return then delete;
run;

 I have the following table:

 

Date      Time       Day      Return

 

03/05    12:20       Sun     2.45

03/05    12:30       Sun     3.23

03/05    12:35       Sun     2.03

03/05    12:40       Sun     2.55

03/05    12:45       Sun     3.11

03/05    12:50       Sun     2.67

03/06    12:25       Mon     2.99

03/06    12:30       Mon     3.09

03/06    12:35       Mon     2.05

03/06    12:40       Mon     2.61

03/06    12:45       Mon     3.32

03/06    12:50       Mon     2.39

...

...

...

03/12    12:20       Sun     2.92

03/12    12:30       Sun     3.13

03/12    12:35       Sun     2.63

03/12    12:40       Sun     2.15

03/12    12:45       Sun     3.51

03/12    12:50       Sun     2.57

 

I want to delete the first observation of each Sunday. What was wrong with my code? A lot more than expected rows got deleted. 52 Sundays in a year times 12 years = 624 observations are supposed to be deleted.

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Sounds like you want FIRST.DAY instead of FIRST.RETURN.  Since you have mulitple values or RETURN for each value of DAY the flag FIRST.RETURN could will be true multiple times on a Sunday. But FIRST.DAY will be true only for the first record for that day.

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

Sounds like you want FIRST.DAY instead of FIRST.RETURN.  Since you have mulitple values or RETURN for each value of DAY the flag FIRST.RETURN could will be true multiple times on a Sunday. But FIRST.DAY will be true only for the first record for that day.

d6k5d3
Pyrite | Level 9

Thanks a lot! Yes, that makes sense. What a stupid SAS beginner I am! 😄

PeterClemmensen
Tourmaline | Level 20

@d6k5d3, far from stupid asking questions in here 😉 Welcome to the SAS communities.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 736 views
  • 1 like
  • 3 in conversation