DATA Step, Macro, Functions and more

Re: Macro for joining tables

Reply
Contributor
Posts: 30

Re: Macro for joining tables

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

Super User
Posts: 17,784

Re: Macro for joining tables

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.

Super User
Super User
Posts: 6,498

Re: Macro for joining tables

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.

Super User
Super User
Posts: 6,498

Re: Macro for joining tables

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

Contributor
Posts: 30

Re: Macro for joining tables

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

Super User
Super User
Posts: 6,498

Re: Macro for joining tables

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

Contributor
Posts: 30

Re: Macro for joining tables

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

Ask a Question
Discussion stats
  • 6 replies
  • 232 views
  • 0 likes
  • 3 in conversation