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-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!

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
  • 3325 views
  • 0 likes
  • 2 in conversation