BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
GKati
Pyrite | Level 9

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;
1 ACCEPTED SOLUTION

Accepted Solutions
GKati
Pyrite | Level 9

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

2 REPLIES 2
FloT
Fluorite | Level 6

Hi,
What if you replace

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

with

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

 ... assuming that &rep is initialized somewhere ?

GKati
Pyrite | Level 9

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;
 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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