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-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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