BookmarkSubscribeRSS Feed
koomalkc
Fluorite | Level 6

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.

%macro samp;

%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;

%end;

%end;

%end;

run;

%mend samp

options mprint;

%samp

Thanks

6 REPLIES 6
Reeza
Super User

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.

Tom
Super User Tom
Super User

Your program is making only 8 output files (because there are 8 values of K).

out=sample&k


If you want each run to generate a different data set then you have to give them unique names.

Tom
Super User Tom
Super User

Why not use the features of SURVEYSELECT to make multiple samples in one file instead using macro code?

koomalkc
Fluorite | Level 6

Tom,

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.

Thanks

Tom
Super User Tom
Super User

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).

koomalkc
Fluorite | Level 6

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.

Thanks

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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