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

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
Meteorite | Level 14

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 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 3 replies
  • 467 views
  • 2 likes
  • 3 in conversation