Hello,
I have a table with millions of rows and I want to compare different samples of rows with different conditions to make sure that my code worked properly. I usually use inobs or outobs options with proc sql and it is very handy. Is there something similar that I could use for many subqueries, like if I want for example, only the first 10 rows for each condition only?
I want something similar to this, but select top doesn't work with proc sql as far as I know
proc sql;
Create table WANT as
(select top 10 *
from HAVE
where condition1)
union all
(select top 10 *
from HAVE
where condition2)
union all
(select top 10 *
from HAVE
where condition3)
;
quit;
Thank you very much
Instead of SQL, can you you use a data step? That would allow for such an approach.
Yes I could use SAS as well, I just tend to use proc sql a lot more
Top 10 is usually used with an ORDER BY isn't it, to get the top 10 records, otherwise if the data order changes your results change?
Is a random selection what you're after?
ORDER BY in conjunction with the OUTOBS option.
"OUTOBS= restricts the number of rows returned from your query, so outobs = 10 would return only the first 10 rows. The full data is evaluated in the query, but the results set is limited in size, which might save on I/O from a database back to SAS. Hope this helps." Linda - @LAP
Related post: Solved: How to select first few records to test the Proc s... - SAS Support Communities
Combine SAS/SQL with SAS dataset options:
proc sql;
create table want as
select *
from
(select * from sashelp.class(obs=5 where=(sex="M")))
union all
(select * from sashelp.class(obs=5 where=(sex="F")));
select * from want;
quit;
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 how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.