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

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?

 


Example.png
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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. 

 

View solution in original post

4 REPLIES 4
Reeza
Super User

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. 

 

akhan205
Calcite | Level 5

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;

Reeza
Super User

Hmm...Why didn't you just do a BY statement for each year instead?

ChrisNZ
Tourmaline | Level 20

> 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

 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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