BookmarkSubscribeRSS Feed
devarayalu
Fluorite | Level 6

data admit;

input a $ b;

cards;

aa 1

aa 3

bb 1

bb 2

dd 1

cc  1

;

proc sort data=admit;

by  a b;

run;

data one;

set admit;

by  a b;

if first.a;

run;

Can any one help what will be the equivalent proc sql code?

Thank you in advance.

4 REPLIES 4
pradeepalankar
Obsidian | Level 7

proc sql;

select  * from (select distinct * from admit) group by a having b=min(b)

order by a;

quit;

devarayalu
Fluorite | Level 6

Thank you so much Pradeep, and need some more information Suppose if we have only one by variable. data one; set admit; by  a; if first.a; run; Then how to select first. observations from the dataset.

PGStats
Opal | Level 21

From the SQL-92 Standard :


A table is a multiset of rows.

multiset: An unordered collection of objects that are not necessarily distinct. The collection may be empty. [my underlying]

Thus any operration that would rely on observation (row) order (first, last, previous, next, etc) cannot be done directly in SQL.

 

PG

PG
Haikuo
Onyx | Level 15

Although some undocumented feature aka monotonic() may help you on this, but If only have ONE variable, how can you tell whether it is the first one in the group or otherwise, it does not make any difference as the end result, so you may just as well use DISTINCT clause to get the same outcome.

Haikuo

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
  • 4 replies
  • 802 views
  • 0 likes
  • 4 in conversation