02-18-2015 12:04 PM
Thanks for your generous help Tom.
I'm running a proc surveyselect code with do loops in macro, and having a same problem as I do in my earlier code. The output I'm getting is replaced by the last table. I'm trying to get 8 different sampled tables. I have been trying hard to get it done since yesterday, but no luck yet.Below is the code.
%do i= 2 %to 3;
%do j=03 %to 12 %by 3;
%do k= 1 %to 8;
proc syrveyselect data=data_201&i.%sysfunc(putn(&j.z2)) method=srs sampsize=500 seed=1992 out=sample&k;
02-18-2015 12:27 PM
Please post a new question rather than continue this question. If they're related feel free to link bank to this question or Branch off to a new discussion.
02-18-2015 05:25 PM
Your program is making only 8 output files (because there are 8 values of K).
If you want each run to generate a different data set then you have to give them unique names.
02-18-2015 09:47 PM
Yes, I want 8 different data set, and I'm getting 8 dataset with the same observations, that is the problem. Isn't that sample1-sample8 are unique names for the output data sets? I'm trying to use SURVEYSELECT to fetch sample form 8 original datasets and want 8 output as a sampled dataset i.e. sample1-sample8 or one single sampled dataset that contains sampled observations from 8 original dataset, either way is good. But I'm getting none of those. I replace out=sample&k with sample without k (omitting counter for k) to make multiple samples in one file as you mentioned, I got one table that is 8th one.
I'm expecting SAS code from you.
02-18-2015 10:38 PM
There are two separate problems here.
1) You are looping over I and J to define the INPUT datasets. And then for a particular input data set you are generating 8 calls to PROC SURVEYSELECT. For each INPUT file you are generating the same 8 output file names. So only the LAST of the INPUT datasets will be used in generating the OUTPUT datasets.
2) You are calling PROC SURVEYSELECT 8 times with the same INPUT dataset and the same input SEED value. So you are re-generating the same "random" sample 8 times.
Did you read the manual on PROC SURVEYSELECT? Please look up how to generate 8 samples in one call. That will fix the second problem.
To fix the first problem you probably need to include &I and &J in the name of the OUTPUT dataset (or datasets if you cannot figure out how the proc works).
02-19-2015 10:03 AM
I have fixed the problem. I was thinking this issue in a more complex way. I replaced output dataset with i and j index, and no using index k. That way the solution was perfect.