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