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

can anyone please help me to get last n obs from each group with out sort the dataset?

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

I was so honor being mentioned by SAS Master  Mr.  NULL .

View solution in original post

8 REPLIES 8
jakarman
Barite | Level 11

It are the first n obs of each group when processing in reversed order.  For small data re-sorting is easy and quickest way.

---->-- ja karman --<-----
Aman4SAS
Obsidian | Level 7

Thanks, but i cant sort the data, i need to get from as data it is.

jakarman
Barite | Level 11

please elaborate your limitations. 
With an external RDBMS there is no physical order defined only logical ordering. In that case a question like this is humbug.
With streaming data you could define a queue of defined size. The lag function of SAS is looking like that. Also a hash can be used for that
Big data with SAS-datasets (relative to your machine) can be processed using a point but than you are losing the first/last options.

What to do if there are less than n records in a group?   

---->-- ja karman --<-----
Aman4SAS
Obsidian | Level 7

Hi, Thanks my issue has been solved.

Should i delete this post?

Haikuo
Onyx | Level 15

No. On the contrary, I think you should share your solution with the forum. So should someone else have the similar issue, the answer becomes available.

Regards,

Haikuo

data_null__
Jade | Level 19

Isn't this same questions showed us the clever solution to within the last month?

Ksharp
Super User

I was so honor being mentioned by SAS Master  Mr.  NULL .

jakarman
Barite | Level 11

To add, the double dow loop http://support.sas.com/resources/papers/proceedings09/038-2009.pdf looks to uses the merge by with a reset at the same position / group order.

In that case you have a generic approach for a sorted dataset. 

---->-- ja karman --<-----

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1286 views
  • 0 likes
  • 5 in conversation