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

 

 

I have no idea how to get started on this. I was thinking of creating an array with DO LOOPS to get the observation but not sure 

where to start it as I am very new to SAS.

 

Please let me know if you need anything else. I will be attaching a sample of my code soon.

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

I would probably do this in two distinct PROC SURVEYSELECT steps like below.

 

I made example data set from sashelp.cars and made arbitrary mileage categories for demonstration purposes

 

data cars;
	set sashelp.cars;
	length mileage $20;
	if mpg_city<16 then mileage='Bad';
	else if 16<=mpg_city<25 then mileage='Fair';
	else if 25<=mpg_city<30 then mileage='Good';
	else mileage='Excellent';
	do i=1 to 100; output; end;
	drop i;
run;

proc sort data=cars;
	by mileage;
run;

proc surveyselect data=cars out=sample1 method=srs n=200 noprint;
	where mileage in ('Bad', 'Excellent');
	strata mileage;
run;

proc surveyselect data=cars out=sample2 method=srs samprate=0.01 noprint;
	where mileage in ('Fair', 'Good');
	strata mileage;
run;

data finalsample;
	set sample1 sample2;
run;

 

View solution in original post

3 REPLIES 3
Reeza
Super User

Try PROC SURVEYSELECT

 

 

PGStats
Opal | Level 21

Look at the strata statement and the Secondary input dataset feature of proc surveyselect.

PG
PeterClemmensen
Tourmaline | Level 20

I would probably do this in two distinct PROC SURVEYSELECT steps like below.

 

I made example data set from sashelp.cars and made arbitrary mileage categories for demonstration purposes

 

data cars;
	set sashelp.cars;
	length mileage $20;
	if mpg_city<16 then mileage='Bad';
	else if 16<=mpg_city<25 then mileage='Fair';
	else if 25<=mpg_city<30 then mileage='Good';
	else mileage='Excellent';
	do i=1 to 100; output; end;
	drop i;
run;

proc sort data=cars;
	by mileage;
run;

proc surveyselect data=cars out=sample1 method=srs n=200 noprint;
	where mileage in ('Bad', 'Excellent');
	strata mileage;
run;

proc surveyselect data=cars out=sample2 method=srs samprate=0.01 noprint;
	where mileage in ('Fair', 'Good');
	strata mileage;
run;

data finalsample;
	set sample1 sample2;
run;

 

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
  • 3 replies
  • 775 views
  • 0 likes
  • 4 in conversation