BookmarkSubscribeRSS Feed
jenim514
Pyrite | Level 9

Hi!

 

I would like some help creating a graph.  I am basically trying to create three lines, bars

 

1.  Bars show the mean of all ER visits by variable 'patientid' during during each year.

2.  Line1 shows the same (mean) but just with 'married' marital status.

3. Line2 show same but with single marital status.

 

I seemed to get the sum (default) to work ok, but when I change the stat to 'mean' it doesnt work correctly.   All response variables are numeric (1) for event...but I gues I want it to sum the events and then graph the mean.  It is just giving me 'mean' of 1 since all events are coded 1.  Should calulate the mean in a separate data step and then do the plot or can i do that within the proc sgplot?  I guess all the visuals could be lines since the means might be similar.

 

 

 

goptions reset=goptions device=png300;  
ods _all_ close;
ods rtf file='asthma.graph13.rtf';
proc sgplot data=asthma.graphvar;
by patientid;
where Visit_type='ER';
vbar year/ response=visit stat=mean fillattrs=(color=gray);
vline year/ response=Married stat=mean lineattrs=(color=black thickness=10);
vline year/ response=Single stat=mean lineattrs=(pattern=solid color=red thickness=10);
run;
ods rtf close;
ods listing;

3 REPLIES 3
ballardw
Super User

You may want to summarize the data so that you have your value and another variable that counts the number of each level of the categorical variable. Then use the Freq= option to tell the procedure to use that value to use the correct number of original observations when calculating the mean. 

PGStats
Opal | Level 21

Something like

 

goptions reset=goptions device=png300;  
ods _all_ close;
ods rtf file='asthma.graph13.rtf';

proc sql;
create table graphvar as
select 
	year,
	sum(Visit) as Visits,
	sum(Married) as Married,
	sum(Single) as Single
from asthma.graphvar
where visit_type = "ER"
group by year;
quit;

proc sgplot data=graphVar;
vbarparm category=year response=Visits / fillattrs=(color=gray);
series x=year y=Married / lineattrs=(color=black thickness=10);
series x=year y=Single / lineattrs=(pattern=solid color=red thickness=10);
run;
ods rtf close;
ods listing;

maybe?

PG
PGStats
Opal | Level 21

Or preferably, for simplicity:

 

goptions reset=goptions device=png300;  
ods _all_ close;
ods rtf file='asthma.graph13.rtf';

data graphData;
set asthma.graphvar;
if Married then status="Married";
if Single then status = "Single";
keep year status;
run;

proc sgplot data=graphData;
vbar year / stat=freq group=status groupdisplay=stack;
run;

ods rtf close;
ods listing;
PG

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
  • 1346 views
  • 0 likes
  • 3 in conversation