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

Hello

I create multiple simple summary reports .

I want to write in the name of the model in the title statement of each report.

So for first report it will be written "Model_mean"

for 2nd report it will be written "Model_max"

for 3rd report it will be written "Model_median"

The name of the model (In title statement) should be taken automatically  from each row table(tbl1,tbl2,tbl3)

 

 

 

data tbl1;
INFILE DATALINES DLM=',';
input ID group $ Y Model $30.;
cards;
1,a,10,Model_mean
2,a,20,Model_mean
3,a,30,Model_mean
4,b,40,Model_mean
5,b,50,Model_mean
6,b,60,Model_mean
;
Run;


data tbl2;
INFILE DATALINES DLM=',';
input ID group $ Y Model $30.;
cards;
1,a,11,Model_max
2,a,21,Model_max
3,a,31,Model_max
4,b,41,Model_max
5,b,51,Model_max
6,b,61,Model_max
;
Run;



data tbl3;
INFILE DATALINES DLM=',';
input ID group $ Y Model $30.;
cards;
1,a,21,Model_median
2,a,31,Model_median
3,a,41,Model_median
4,b,51,Model_median
5,b,61,Model_median
6,b,71,Model_median
;
Run;


%macro RRR;
%do j=1 %to 3;
PROC SQL;
	create table summary&J.  as
	select  group,
            sum(Y) as SUM_Y 
	from  tbl&j.
	group by group
;
QUIT;
title "I want to write here the name of the model";
proc print data=summary&J. noobs;Run;
%end;
%mend RRR;
%RRR;

 

1 ACCEPTED SOLUTION

Accepted Solutions
gamotte
Rhodochrosite | Level 12

Hello,

 

%macro RRR;
%do j=1 %to 3;
PROC SQL noprint;
	create table summary&J.  as
	select  group,
            sum(Y) as SUM_Y 
	from  tbl&j.
	group by group
    ;
	select Model into :model from tbl&j. where monotonic()=1;
QUIT;
title "&model.";
proc print data=summary&J. noobs;Run;
%end;
%mend RRR;
%RRR;

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

Create a macro variable from the dataset:

PROC SQL noprint;
	create table summary&J.  as
	select  group,
            sum(Y) as SUM_Y 
	from  tbl&j.
	group by group
;
select model into :model from tbl&j.;
QUIT;
title "&model";
Ronein
Onyx | Level 15

Thank you. It is working great

gamotte
Rhodochrosite | Level 12

Hello,

 

%macro RRR;
%do j=1 %to 3;
PROC SQL noprint;
	create table summary&J.  as
	select  group,
            sum(Y) as SUM_Y 
	from  tbl&j.
	group by group
    ;
	select Model into :model from tbl&j. where monotonic()=1;
QUIT;
title "&model.";
proc print data=summary&J. noobs;Run;
%end;
%mend RRR;
%RRR;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1096 views
  • 2 likes
  • 3 in conversation