I am able to create many types of bar charts in SAS but the simplest is escaping my grasp.
A subset of my data looks somewhat like this:
Year Var1 Var2 Var3
2004 0.50 0.38 0.93
2005 0.40 0.22 0.88
I want to create (for each year) a simple bar chart that has 3 bars, one for each variable and along the same axis for its respective value, but it seems like I am able to plot everything except what I'm trying to accomplish. This is easily done in Excel but I am automating the process since I need to make many charts (I need no assistance with automation). I have tried using Year as one of the variables (after limiting my plotting to certain years using a where statement) but still to no avail. Any advice?
Why not transpose the data to a long format, via PROC TRANSPOSE. Probably the easiest method.
If you're using SAS Graph see the examples here
http://robslink.com/SAS/democd6/aaaindex.htm
Otherwise, see the SGPLOT examples in the graph gallery
https://support.sas.com/sassamples/graphgallery/PROC_SGPLOT.html
If you navigate up from either of those links you'll see more examples.
Why not transpose the data to a long format, via PROC TRANSPOSE. Probably the easiest method.
If you're using SAS Graph see the examples here
http://robslink.com/SAS/democd6/aaaindex.htm
Otherwise, see the SGPLOT examples in the graph gallery
https://support.sas.com/sassamples/graphgallery/PROC_SGPLOT.html
If you navigate up from either of those links you'll see more examples.
Thank you for the tranpose idea! This is what ultimately worked:
proc transpose data=chart out=dataset;
id year;
run;
%macro year (inp = );
%do i=2001 %to 2012;
title "&inp. &i.";
proc gchart data=dataset;
where _name_ in ("&inp.var1","&inp.var2","&inp.var3");
vbar _name_ / sumvar = _&i.;
run;
%end;
%mend year;
Hmm...Why didn't you just do a BY statement for each year instead?
> A subset of my data looks somewhat like this
Excel "data" is not data. It is a actually a report.
You need to make it into usable data by creatting proper variables that you can then plot.
See what the data looks like in the links given by @Reeza
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.