Hi,
I have the following code, which I need to run multiple times (i=1 to 100) on different datasets. I need to save the datasets separately. How can I do this most efficiently?
Thanks,
****************************************
data claims_1;
input client year cost contract;
datalines;
18 2011 589.92 10.2
19 2010 1629.8 11.5
20 2011 1813.29 2.3
21 2012 412.06 3.2
22 2012 219.82 0.4
23 2010 3669.98 5.9
24 2012 4879.63 6.8
;
run;
/*GENERAL HOSPITALS*/
proc glm data=claims_1;
class year (ref='2010' );
model cost=year|contract/ solution;
ods output ParameterEstimates=work.parmest_1 fitstatistics=fit_1 nobs=nobs_1;
run;
data parmest_1;
set parmest_1;
rename Parameter=Variable;
run;
data parmest_1;
set parmest_1;
numord+1;
if first.variable then numord=1;
run;
data nobs_1;
set nobs_1;
if label^="Number of Observations Used" then delete;
keep Nobsused Variable numord;
Variable="N. Obs.";
rename NObsUsed=Estimate;
numord=2000;
run;
data fit_1;
set fit_1;
keep RSquare RootMSE;
run;
proc transpose data=fit_1 out=fit_1;
run;
data fit_1;
set fit_1;
if _Name_="RSquare" then numord=1000;
if _Name_="RootMSE" then numord=1001;
rename _Label_=Variable;
drop _name_;
rename col1=Estimate;
run;
data work.parmest1;
set work.parmest_1;
run;
** append parmest_1;
proc datasets;
append base=work.parmest1 data=work.nobs_1 force;
run;
append base=work.parmest1 data=work.fit_1 force;
run;
quit;
Options generally go at the top of your program.
options mprint symbolgen;
%macro demo (n=);
%do i=1 %to &n;
%put &n;
%put &n_new;
%end;
%mend;
%demo(n=8);
This is what i have so far. This doesn't produce any output, without any error messages.
%macro do_all;
%do i=1 %to 2;
data work.parmest_&i_new;
set work.parmest_&i;
rename Parameter=Variable;
run;
data parmest_&i;
set parmest_&i;
numord+1;
if first.variable then numord=1;
run;
data nobs_&i;
set nobs_&i;
if label^="Number of Observations Used" then delete;
keep Nobsused Variable numord;
Variable="N. Obs.";
rename NObsUsed=Estimate;
numord=2000;
run;
data fit_&i;
set fit_&i;
keep RSquare RootMSE;
run;
proc transpose data=fit_&i out=fit_&i;
run;
data fit_&i;
set fit_&i;
if _Name_="RSquare" then numord=1000;
if _Name_="RootMSE" then numord=1001;
rename _Label_=Variable;
drop _name_;
rename col1=Estimate;
run;
data work.parmest1;
set work.parmest_&i;
run;
** append parmest_&i;
proc datasets;
append base=work.parmest1 data=work.nobs_&i force;
run;
append base=work.parmest1 data=work.fit_&i force;
run;
quit;
%end;
%mend do_all;
Run it with the following options:
options mprint symbolgen;
And make sure you call the macro.
There's no %do_all; at the end that would indicate you ran the macro code.
EDIT:
And in general, don't do this:
data work.parmest_&i_new;
set work.parmest_&i;
I's in the middle make it harder to manage, and when you put it in the middle you need a colon to identify the end, otherwise, how does SAS know if the macro variable is:
&i or &i_new?
Options generally go at the top of your program.
options mprint symbolgen;
%macro demo (n=);
%do i=1 %to &n;
%put &n;
%put &n_new;
%end;
%mend;
%demo(n=8);
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.