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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 1277 views
  • 1 like
  • 2 in conversation