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;
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;
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";
Thank you. It is working great
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.