BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
raheleh22
Obsidian | Level 7

Hi 

I have the below code, but instead of summer, i want to have the mean var of spi. Also, how can I give annotations ( like each color presenting which location)? 

axis1 label=(h=0.17 in f=triplex "SPI and count by Year and location")
value=(h=0.135 in f=triplex) minor=none value=(h=0.07 in f=triplex a=-45)
color=black;
axis3 label=none;
proc gbarline data=totalc;
bar Year/ sumvar=SPI subgroup=loc width=2 discrete no frame space=1 axis=axis2 maxis=axis1;
plot /sumvar=count axis=axis3;
run;
quit;

1 ACCEPTED SOLUTION

Accepted Solutions
raheleh22
Obsidian | Level 7

This is very helpful and fixed the issue. Thanks a lot. 

View solution in original post

9 REPLIES 9
Reeza
Super User
I would recommend switching to SGPLOT if possible and using a Data Attribute Map in that case.

You may need to pre-summarize your data though.
https://documentation.sas.com/doc/en/vdmmlcdc/8.11/grstatproc/n18szqcwir8q2nn10od9hhdh2ksj.htm
raheleh22
Obsidian | Level 7

I tried that in different ways but I could not make clusters or plots by different variables. with this code i could get the graph and summery the data i want as below: 

raheleh22_0-1687203453977.png

but now the problem is the precipitation is sum and I want mean. I was able to add annotations. 

DanH_sas
SAS Super FREQ

@Reeza is correct. Run the example below and see if this is the desired output. Your data should fit into this pattern. You can also add a discrete attribute map to this example if you want to control the assignment of particular colors to group values.

 

Hope this helps!

Dan

 

proc summary data=sashelp.cars nway;
class origin model;
var msrp;
output out=barcars mean=mean_msrp;
run;

proc summary data=sashelp.cars nway;
class origin;
var horsepower;
output out=linecars mean=mean_power;
run;

data cars;
merge barcars linecars;
by origin;
run;

proc sgplot data=cars;
y2axis min=0 offsetmin=0;
yaxis offsetmin=0;
vbarparm category=origin response=mean_msrp / 
         group=model groupdisplay=cluster;
series x=origin y=mean_power / y2axis markers;
run;
raheleh22
Obsidian | Level 7

this is really helpful, but there is a problem. i have my code below, for some reason the calculation of my count_sum is not correct in fact the count sum should be the total of counts per year per location but what this code is giving me is different number ( it is giving the sum of counts per year it is not stratified by loc). 

proc summary data=totalc nway;
class loc year;
var spi;
output out=spimean mean=mean_spi;
run;

proc summary data=totalc nway;
class year;
var count;
output out=countsum sum=count_sum;
run;
proc sgplot data=totalnew;
y2axis min=0 offsetmin=0;
yaxis offsetmin=0;
vbarparm category=year response=mean_spi /
group=loc groupdisplay=cluster;
series x=year y=count_sum / y2axis markers;
run;

DanH_sas
SAS Super FREQ

Your CLASS statement needs to have "year loc", not "loc year". That's what is causing the miscalculation.

raheleh22
Obsidian | Level 7

This is very helpful and fixed the issue. Thanks a lot. 

raheleh22
Obsidian | Level 7

after fixing the issue, 

I wonder if there is a way I can give color or shape to my circle dots in the below graph. now my bar has a color which is indicating the measure of spi by loc but my circle dots are all the same so it is not expressing count by loc. Is there a way to specify that too? 

raheleh22_0-1687262593357.png

 

DanH_sas
SAS Super FREQ

If you want the plot to be group-sensitive, get rid of the proc summary  and data step calls and simply run the following code:

 

proc sgplot data=totalc;
y2axis min=0 offsetmin=0;
yaxis offsetmin=0;
vbar year / response=spi stat=mean group=loc groupdisplay=cluster;
vline year / response=count stat=sum group=loc y2axis markers;
run;
raheleh22
Obsidian | Level 7

It is fixed now. Thank you

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
  • 9 replies
  • 704 views
  • 4 likes
  • 3 in conversation