BookmarkSubscribeRSS Feed
VCM
Obsidian | Level 7 VCM
Obsidian | Level 7

I have a proc template within a macro.  The data is subset based on the value of VAR (if VAR = 1, or 2, or 3, etc.)  This produces a 5-page bar graph with one VAR group on each page.  The bars are the same color on each page (red), but I want them to be different colors.

 

I've read some similar threads in this group, which included using DATACONTRASTCOLORS, but that apparently doesn't work in 9.2 as I got an error when I added it.  I need to make the value of the color a macro variable, so I can change it with each call of the macro.

 

Is there some way to force bar colors in 9.2?

3 REPLIES 3
ballardw
Super User

You really should show the code for the template, assuming that is a template used by SGrender. If you are using another procedure such as SGplot or Sgpanel show that code. With 9.2 you may want to move to Sgrender to have more control.

A little example data may help as well.

 

If using Sgrender a dynamic variable to pass the color to the template would work.

Jay54
Meteorite | Level 14

You should be able to use GROUP=VAR in the VBAR statement.  Also set UNIFORM=GROUP in the proc statement.  This will make all bars in one graph with BY=VAR. 

 

ods _all_  close;
ods html;
proc sort data=sashelp.class out=class;
by  sex;
run;

proc sgplot data=class uniform=group;
  by sex;
  vbar name / response=height group=sex;
run;
ods html close;

 

 

With GTL, you can use the INDEX= option.  Create a new column "Index" with values 1 for Males and 2 for Females.  Then set INDEX=index on the BarChart statement. 

VCM
Obsidian | Level 7 VCM
Obsidian | Level 7

Thanks for the input, everyone!

 

First, the code belongs to my client and I'm not able to share a lot of detail--just the overall logic.

Second, this isn't even my project; I just jumped in to help and now my curiousity has gotten the best of me. 😉 

 

The output is 6 pages.  Page 1 is a waterfall all 5 values of VAR, each a different color:

VAR = 1 then red

VAR = 2 then blue

VAR = 3 then yellow

VAR-= 4 then green

VAR = 5 then purple

 

Pages 2 through 6 are 1 VAR each, and we want the colors to match what is on page 1; so page 2 (VAR = 1) will be red, page 3 (VAR = 2) will be blue, etc.

 

It seems that the overall issue is how the macros are set up:

  1. A proc template is called to create the style "STYLEX", using "replace GraphData1" etc. to set the 5 colors for page 1.
  2. A proc template is called to create the format for the page 1 waterfall
  3. Proc sgrender creates page 1 from the dataset
  4. A macro is created to subset the dataset by value of VAR (if VAR = &val)
  5. A proc template (still within the macro) is called to create the format for the pages 2-6 waterfalls
  6. Proc sgrender (still within the macro) creates the page
  7. Macro is called 5 times, once for each value of VAR
  8. Another macro combines all 6 pages into one output--and this macro calls STYLEX.  Since pages 2 through 6 only have one value of VAR, each one gets treated like VAR = 1 and is assigned red.

 

I think what we might need to do is find a way to alter that final macro so that we can create each page in a different style, THEN combine them.

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