BookmarkSubscribeRSS Feed
Ananth_kumar
Calcite | Level 5
%macro create_trend_line(entity,x,y,width,height,chart_title,axis_label);
 
%_f_define_region(&x,&y,&width,&height);
 
  proc sql noprint;
     select distinct Yr_nb
into:year1-
from trend_lines_ctrl_srt
where Entity="&entity.";
  quit;
 
    proc sql;
        create table trend_data as
            select Yr_nb,
                   Mo_Name, 
                   Ctrl_MBR
            from trend_lines_ctrl_srt
            where Entity = "&entity."
            order by Yr_nb, 
                     case Mo_Name
                         when 'JAN' then 1
                         when 'FEB' then 2
                         when 'MAR' then 3
                         when 'APRIL' then 4
                         when 'MAY' then 5
                         when 'JUN' then 6
                         when 'JULY' then 7
                         when 'AUG' then 8
                         when 'SEP' then 9
                         when 'OCT' then 10
                         when 'NOV' then 11
                         when 'DEC' then 12
                         else 13
                     end;
             quit;
     footnote;
  
    proc sgplot data=trend_data noautolegend;
styleattrs datacolors=(red blue black);
       series x=Mo_Name y=Ctrl_MBR / group=Yr_nb lineattrs=(thickness=2);
           xaxis label="Month" type=discrete;
           yaxis label="MBR Rate";
   title "&chart_title";
           keylegend / title="Years" position=bottom;
    run;
    title;
%mend create_trend_line;

 

I created this macro to generate trendline for years in the dataset, but unable to define custom colors.

6 REPLIES 6
ballardw
Super User

Will you have the same values of Yr_nb all the time? Then look up DATTRMAP= data set option for Proc SGplot to create set of properties such as line color for the values of Yr_nb. That would make the colors consistent across many graphs.

 

If you want that list in the styleattrs use DATACONTRASTCOLORS instead of datacolors.

Ananth_kumar
Calcite | Level 5

I have 3 years in Yr_nb = 2019 2022 and 2023 and the month on month the values for yaxis ctrl_mbr changes. I'm trying to apply a single color for 2019,2022 and 2023

PaigeMiller
Diamond | Level 26

I think in STYLEATTRS you want to use DATACONTRASTCOLORS=() and not DATACOLORS=()

 

 

--
Paige Miller
Ananth_kumar
Calcite | Level 5

will this defines color for each year ? Thanks for responding

PaigeMiller
Diamond | Level 26

will this defines color for each year ? Thanks for responding

 

You can try it and find out

--
Paige Miller
ballardw
Super User

@Ananth_kumar wrote:

will this defines color for each year ? Thanks for responding


Kind of depends on your data and what you place in the options. If your data has more group values then you supply on the list for Datacontrastcolors then you are back to colors from your active style and may duplicate. Or if you place the same color in the list more than once it may be pretty hard to tell.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 910 views
  • 1 like
  • 3 in conversation