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;
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);
ods rtf close;
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.
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;
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;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.