If you are using the TOP syntax of T-SQL, then unless you include an order by statement, the rows are returned arbitrarily (see http://msdn.microsoft.com/en-us/library/ms189463.aspx). If you are including an order by, that suggests you want the one record returned that is the min (or max) of date column.
If this is representative of the data (tabA):
NameVal NameDate OtherVar1 OtherVar2 name1 8/27/10 A F name1 9/15/10 B G name2 8/22/10 C H name2 8/22/10 C1 H1 name2 10/22/10 D I
proc sql;
select
a.nameval,
a.namedate,
a.othervar1,
a.othervar2
from tabA as A
where a.NameDate =
(select min(NameDate)
from TabA where nameval = a.nameval);
quit;
This would return
NameVal NameDate OtherVar1 OtherVar2 name1 8/27/10 A F name2 8/22/10 C H name2 8/22/10 C1 H1
Note that this treats ties exactly like the top 1 statement would.
If that isn't what you're trying to do, then perhaps some clarification would help.
proc sql;
create table top as
select region,sales
from sashelp.shoes
group by region
having
sales eq max(sales)
;
quit;
Ksharp
If you are using the TOP syntax of T-SQL, then unless you include an order by statement, the rows are returned arbitrarily (see http://msdn.microsoft.com/en-us/library/ms189463.aspx). If you are including an order by, that suggests you want the one record returned that is the min (or max) of date column.
If this is representative of the data (tabA):
NameVal NameDate OtherVar1 OtherVar2 name1 8/27/10 A F name1 9/15/10 B G name2 8/22/10 C H name2 8/22/10 C1 H1 name2 10/22/10 D I
proc sql;
select
a.nameval,
a.namedate,
a.othervar1,
a.othervar2
from tabA as A
where a.NameDate =
(select min(NameDate)
from TabA where nameval = a.nameval);
quit;
This would return
NameVal NameDate OtherVar1 OtherVar2 name1 8/27/10 A F name2 8/22/10 C H name2 8/22/10 C1 H1
Note that this treats ties exactly like the top 1 statement would.
If that isn't what you're trying to do, then perhaps some clarification would help.
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.
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.