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;
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;
Hi,
What if you replace
rep =(&i*&rep)+&rep
with
reps =%eval((&i*&rep)+&rep)
... assuming that &rep is initialized somewhere ?
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;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.