BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi,

i need first and last observations in by group using proc sql;

Ex:
I have three variables A,B,C. i need the out put first and last variables of B and group by A , B.
101 140 220
101 142 230
101 148 259
101 145 258
102 123 339
102 229 332
102 227 389


output:
101 140 220
101 148 259
102 123 339
102 229 332

Thanks & Regards
Slone
3 REPLIES 3
LinusH
Tourmaline | Level 20
Since SQL is a column based language, doing calculations according to row numbers is not SQL's cup of tea. Maybe you can do some complicated query using the unsupported monotonic function. But, this is so much easier done with data step. Do you have reason for not using the data step?

/Linus
Data never sleeps
deleted_user
Not applicable
Thank u LINUS

i have a dataset size 100GB and 400 variables. if i run proc sort it will take 4 hours. and agian i need to run data step for first.variable and last.variable. thats why i need other than this process.



Thank's & Regards
Slone
LinusH
Tourmaline | Level 20
Well, not so surprisingly, SQL needs also to do a sort before it does group by, so I don't think you are gaining so much, just because you don't explicitly code a sort.
If you are concerned about I/O, maybe you could try a SQL ORDER BY view, which probably result in fewer R/W operations. Be sure to use as much memory as possible to minimize swapping.

/Linus
Data never sleeps

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 3508 views
  • 0 likes
  • 2 in conversation