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

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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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);

View solution in original post

4 REPLIES 4
GKati
Pyrite | Level 9

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;

 

Reeza
Super User

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?

 

 

 

 

GKati
Pyrite | Level 9
Thx for your reply.
1. where do I put this option? Before the first data step?If so, I'm still getting error msgs "The symbol is not recognized and will be ignored."

2. I got this now, thx
Reeza
Super User

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);

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 4 replies
  • 1346 views
  • 1 like
  • 2 in conversation