Hi i have data like this
METHOD | DAYS |
A | 0 |
B | 1 |
A | 0 |
C | 2 |
C | 0 |
A | 4 |
B | 1 |
C | 0 |
B | 0 |
A | 0 |
And sgplot like this:
proc format;
value days
0='Same day'
1='Next day'
2-3 = '+2 days'
4-high = '+4 days';
run;
PROC SGPLOT DATA = Merged_1 PCTLEVEL=GROUP NOBORDER NOWALL NOCYCLEATTRS ;
format dato ddmmyy.;
VBAR METHOD / GROUP = days stat= percent NOOUTLINE;
TITLE 'TEST';
keylegend / title="";
XAXIS DISPLAY=(NOLABEL);
YAXIS DISPLAY=(NOLABEL);
format days days.;
styleattrs DATACOLORS=('#CBE5A1' '#FFFF00' mistyrose firebrick );
run;
I want a table under the sgplot that looks like this - the count of how many same day, next day etc.:
A | B | C | |
Same day | 3 | 1 | 2 |
next day | 0 | 2 | 0 |
+2 days | 0 | 0 | 1 |
+4 days | 1 | 0 | 0 |
Hope you can help
data merged_1;
length method $1;
input method days;
datalines;
A 0
B 1
A 0
C 2
C 0
A 4
B 1
C 0
B 0
A 0
;
run;
proc format;
value days
0='Same day'
1='Next day'
2-3 = '+2 days'
4-high = '+4 days';
run;
proc freq data=merged_1 noprint;
table method*days / out=summarized sparse;
format days days.;
run;
PROC SGPLOT DATA = summarized PCTLEVEL=GROUP NOBORDER NOWALL NOCYCLEATTRS ;
VBAR METHOD / response = count GROUP = days NOOUTLINE;
keylegend / title="";
XAXIS DISPLAY=(NOLABEL);
YAXIS DISPLAY=(NOLABEL);
styleattrs DATACOLORS=('#CBE5A1' '#FFFF00' mistyrose firebrick );
xaxistable count ;
format days days.;
run;
This works for me, I pre-summarized the data and followed this blog post:
https://blogs.sas.com/content/graphicallyspeaking/2017/04/04/consistent-ordering-graph-components/
Se the first post
proc format;
value days
0='Same day'
1='Next day'
2-3 = '+2 '
4-high = '+4 ';
run;
PROC SGPLOT DATA = comp PCTLEVEL=GROUP NOBORDER NOWALL NOCYCLEATTRS ;
format dato ddmmyy.;
VBAR method / GROUP = days stat= percent NOOUTLINE;
TITLE 'A';
keylegend / title="";
XAXIS DISPLAY=(NOLABEL);
YAXIS DISPLAY=(NOLABEL);
FORMAT days days.;
styleattrs DATACOLORS=('#CBE5A1' '#FFFF00' mistyrose firebrick );
run;
It doesnt work 🙂
It messes up the plot
when I put xaxistable Days;
proc format;
value days
0='Same day'
1='Next day'
2-3 = '+2 days'
4-high = '+4 days';
run;
PROC SGPLOT DATA = Merged_1 PCTLEVEL=GROUP NOBORDER NOWALL NOCYCLEATTRS ;
format date ddmmyy.;
VBAR method/GROUP = days stat= percent NOOUTLINE;
TITLE 'tets';
keylegend / title="";
XAXIS DISPLAY=(NOLABEL);
YAXIS DISPLAY=(NOLABEL);
FORMAT days days.;
xaxistable Days;
styleattrs DATACOLORS=('#CBE5A1' '#FFFF00' mistyrose firebrick );
run;
it gives me this
same day | same day | same day | same day |
next day | +4 days | +2 days | +4 days |
+2 days | +4 days | +4days | +4 days |
+4 days | +4days | +4days |
which is not correct.
The table should count the days value shown in the table in the question?
How can i do that
Is there no help to get here ?
Moved your post to the graphics forum.
Perhaps someone will be able to answer there.
data merged_1;
length method $1;
input method days;
datalines;
A 0
B 1
A 0
C 2
C 0
A 4
B 1
C 0
B 0
A 0
;
run;
proc format;
value days
0='Same day'
1='Next day'
2-3 = '+2 days'
4-high = '+4 days';
run;
proc freq data=merged_1 noprint;
table method*days / out=summarized sparse;
format days days.;
run;
PROC SGPLOT DATA = summarized PCTLEVEL=GROUP NOBORDER NOWALL NOCYCLEATTRS ;
VBAR METHOD / response = count GROUP = days NOOUTLINE;
keylegend / title="";
XAXIS DISPLAY=(NOLABEL);
YAXIS DISPLAY=(NOLABEL);
styleattrs DATACOLORS=('#CBE5A1' '#FFFF00' mistyrose firebrick );
xaxistable count ;
format days days.;
run;
This works for me, I pre-summarized the data and followed this blog post:
https://blogs.sas.com/content/graphicallyspeaking/2017/04/04/consistent-ordering-graph-components/
Looks like your data needs some manipulation/summarization in order to print the table you're wanting. There might be a slick/automated way to do that with proc tabulate or something ... but here's one way to do it with "brute force" ...
data merged_1;
length method $1;
input method days;
datalines;
A 0
B 1
A 0
C 2
C 0
A 4
B 1
C 0
B 0
A 0
;
run;
proc format;
value days
0='Same day'
1='Next day'
2-3 = '+2 days'
4-high = '+4 days';
run;
PROC SGPLOT DATA = Merged_1 PCTLEVEL=GROUP NOBORDER NOWALL NOCYCLEATTRS ;
VBAR METHOD / GROUP = days stat= percent NOOUTLINE;
TITLE 'TEST';
keylegend / title="";
XAXIS DISPLAY=(NOLABEL);
YAXIS DISPLAY=(NOLABEL);
format days days.;
styleattrs DATACOLORS=('#CBE5A1' '#FFFF00' mistyrose firebrick );
run;
proc sql noprint;
create table summary_table as
select unique method, days, count(*) as count
from merged_1
group by method, days;
quit; run;
proc sort data=summary_table out=summary_table;
by days;
run;
proc transpose data=summary_table out=summary_table;
by days;
id method;
run;
proc print data=summary_table (drop=_name_) label noobs;
label days='00'x;
format days days.;
run;
Thank you can I make the sgplot and table as one PNG?
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!
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.