02-22-2015 09:20 AM
Hallo SAS community.
I am stuck with a problem i hope you can help me with.
I have created the code:
proc surveyselect data= xxx.X201202 method=srs n=200 seed=200
Where department ne "AgroTech A/S";
However, i want to create a macro which loop through the data set
If the variable "Initials" from the sample1-6 is the same as initials in xxx.X201202 then these observationses should not be a part of the random sample of 200.
I hope you can help me.
02-22-2015 11:35 AM
I don't understand your question. If you simply want to randomly assign people to six different groups, without replication, then take a look at: 36383 - Randomly assign the observations in a data set to two or more groups
02-22-2015 01:51 PM
You have to indicate what you are trying to do. You're macro creates a local macro variable six times, each time discarding the previous version. I don't understand its purpose.
Your 2nd where statement doesn't make sense (to me). While you have shown any example data, a statement like:
where initialer ne 1, 3, 5;
I suggest you post some sample data, explain what you want to accomplish and, based on the sample data, what resulting file you want to obtain.
02-23-2015 12:48 PM
Hallo again and thank you for your patience.
Data set 1
Data set 2
Data set 3
What I am trying to do is to make an random sample of "data set 1".
However, I do not want to include observations with the same initials from data set 2 and 3. Therefore the random sample must not include obs 2 and 5, because their initials occur in data set 2 and 3.
02-23-2015 01:26 PM
Sounds like you are trying to do something like the following:
set sample1 sample2 sample3 sample4 sample5 sample6;
proc sql noprint;
select distinct quote(strip(initials))
into :initials separated by ','
proc surveyselect data=x201202 method=srs n=200 seed=200
where afdeling ne "AgroTech A/S" and
initialer not in (&initials.);
02-25-2015 01:40 PM
So, what I understand is that you already have samples and you want the new sample to exclude cases already selected. Try this (not tested) :
/* Create a set of existing samples */
data sampSet / view=sampSet;
/* Create a subset of x201202 excluding existing samples */
create view newSet as
initials not in (select initials from sampSet);
/* Create a new sample from X201202, excluding previous samples */
call surveyselect data=newSet method=srs n=200 seed=200 out=test005;