DATA Step, Macro, Functions and more

Replicate number in PROC SURVEYSELECT in a macro

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 109
Accepted Solution

Replicate number in PROC SURVEYSELECT in a macro

Dear SAS users,

 

I am generating samples using SURVEYSELECT and then running PROC GLM with a BY command, all of this in a MACRO to save the results in indivudal files.

 

I want the repetition variable, which goes from 1... n in each iteration to start where the other iteration left off.

 

So:

if i=1 then  rep=1, ...,5

if i=2 then  rep=6,...10

if i=3 then rep=11...15

etc.

 

I would make the REP option in my code equal to REP=(&i*&rep)+&rep which would give me this result, but that doesn't seem to be recognized as a symbol.

 

Any ideas on how to achieve the same result?

%macro do_survey;
options mprint symbolgen;
%do i=0 %to 2;

proc surveyselect data=claims out=bootsample
     seed = 1347 method = urs
	 samprate = 1 outhits rep =(&i*&rep)+&rep;
run;

ods listing close;

proc glm data=Bootsample;
class year(ref='2010' ) age_gr (ref='0' );
model indavgcost= year|avgcontract/ solution;
TITLE "ALL HOSPITALS-indavgcost";
by replicate;
ods output ParameterEstimates=work.t_&i;
run;

data t_&i;
set t_&i;
keep replicate parameter estimate;
run;

data t_&i;
set t_&i;
if estimate=0 then delete;
run;

proc datasets;
append base=t1 data=t_&i force;
run;
quit;

%end;
%mend do_survey;

%do_survey;

Accepted Solutions
Solution
‎04-10-2018 09:49 AM
Frequent Contributor
Posts: 109

Re: Replicate number in PROC SURVEYSELECT in a macro

Thanks for the responses. It does run with rep=%eval()..., but it does't give me the desired result after all.

 

I ended up creating a new variable in a subsequent data step. This works well.

%macro do_survey;
options mprint symbolgen;
%do i=0 %to 2;

proc surveyselect data=claims out=bootsample
     seed = 1347 method = urs
	 samprate = 1 outhits rep =&rep;
run;

ods listing close;

proc glm data=Bootsample;
class year(ref='2010' ) age_gr (ref='0' );
model indavgcost= year|avgcontract/ solution;
TITLE "ALL HOSPITALS-indavgcost";
by replicate;
ods output ParameterEstimates=work.t_&i;
run;

data t_&i;
set t_&i;
keep replicate parameter estimate;
run;

data t_&i;
set t_&i;
if estimate=0 then delete;
rep2=(&i*&rep)+replicate;
run;

proc datasets;
append base=t1 data=t_&i force;
run;
quit;

%end;
%mend do_survey;

%do_survey;
 

View solution in original post


All Replies
Occasional Contributor
Posts: 8

Re: Replicate number in PROC SURVEYSELECT in a macro

[ Edited ]

Hi,
What if you replace

rep =(&i*&rep)+&rep

with

reps =%eval((&i*&rep)+&rep)

 ... assuming that &rep is initialized somewhere ?

Solution
‎04-10-2018 09:49 AM
Frequent Contributor
Posts: 109

Re: Replicate number in PROC SURVEYSELECT in a macro

Thanks for the responses. It does run with rep=%eval()..., but it does't give me the desired result after all.

 

I ended up creating a new variable in a subsequent data step. This works well.

%macro do_survey;
options mprint symbolgen;
%do i=0 %to 2;

proc surveyselect data=claims out=bootsample
     seed = 1347 method = urs
	 samprate = 1 outhits rep =&rep;
run;

ods listing close;

proc glm data=Bootsample;
class year(ref='2010' ) age_gr (ref='0' );
model indavgcost= year|avgcontract/ solution;
TITLE "ALL HOSPITALS-indavgcost";
by replicate;
ods output ParameterEstimates=work.t_&i;
run;

data t_&i;
set t_&i;
keep replicate parameter estimate;
run;

data t_&i;
set t_&i;
if estimate=0 then delete;
rep2=(&i*&rep)+replicate;
run;

proc datasets;
append base=t1 data=t_&i force;
run;
quit;

%end;
%mend do_survey;

%do_survey;
 
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 114 views
  • 1 like
  • 2 in conversation