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

 

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
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/

 

View solution in original post

11 REPLIES 11
mmea
Quartz | Level 8

Se the first post

Reeza
Super User
XAXISTABLE, see example at the bottom of the documentation.

I'd first try adding this code to my PROC
xaxistable Days / stat=freq;

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=grstatproc&docsetTarget=p...


mmea
Quartz | Level 8

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 

 

 

Reeza
Super User
Does not work is vague and uninformative.

If you want help with the actual code provide sample data, your code and log. The code shown does not include an XAXISTABLE so obviously it wouldn't work but I have no idea what you tried or did.
Reeza
Super User
Not really sure why you started a new thread but I've merged the two.
mmea
Quartz | Level 8

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

mmea
Quartz | Level 8

Is there no help to get here ?

Reeza
Super User

Moved your post to the graphics forum. 
Perhaps someone will be able to answer there. 

Reeza
Super User
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/

 

GraphGuy
Meteorite | Level 14

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;

 

table.png

 

mmea
Quartz | Level 8

Thank you can I make the sgplot and table as one PNG?

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 11 replies
  • 3243 views
  • 3 likes
  • 3 in conversation