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.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.