BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jigsatics
Calcite | Level 5

Hi,

 

I have a SAS code that looks like this:

PROC SQL;
create table CombinedSample as
	(select account_number, 'Cell1' as seed 
		from Dataset1
	where age between 16 and 34)

union 

(select account_number, 'Cell2' as seed
		from Dataset1
	where age between 35 and 54)
;
QUIT;

I have 10 or more similar select statements that will be included in the code. My question is how can I limit the output for each  select statement?  For example, for Cell1 i only need 50 and for Cell2 128, etc.

 

Someone here used limit statements but it only works on AQT.

 

TIA!

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Do it after, with surveyselect. Stratify with seed. You will have full control of sample sizes and the assurance that observations are selected randomly.

PG

View solution in original post

5 REPLIES 5
collinelliot
Barite | Level 11

And you don't care which rows they are, as long as there are only 50, for example, in the first query?

 

I don't know what all the other queries look like, but for what you've shown, try adding the following to the where statement:

 

PROC SQL;
create table CombinedSample as
	(select account_number, 'Cell1' as seed 
		from Dataset1
	where age between 16 and 34 AND
                  monotonic() <= 50)

union 
jigsatics
Calcite | Level 5

The other queries will be similar to the first 2 but with a slightly different where statement. The idea is to get a random 50. Does the monotonic function randomly pick 50?

collinelliot
Barite | Level 11

Given what you want, PGStats approach is the right way to go.

ChrisBrooks
Ammonite | Level 13

Try the inobs= or outobs= options e.g. 

 

proc sql outobs=3;
	create table classmall
	as select *
	from sashelp.class
	where sex='M';
quit;

proc sql inobs=3;
	create table classmall
	as select *
	from sashelp.class
	where sex='M';
quit;
PGStats
Opal | Level 21

Do it after, with surveyselect. Stratify with seed. You will have full control of sample sizes and the assurance that observations are selected randomly.

PG

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 998 views
  • 1 like
  • 4 in conversation