BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ravindra_
Quartz | Level 8
/*subsetting the table to get only subjid, visit and visiopro	*/
 proc sql;
 create table pro as
 select *
 from ana.PRO_F_ADQS2(keep=d_SUBJID d_VISITN d_VPD5_Tot)
 where d_SUBJID IN ( '05-07','05-08','05-09','05-10','05-11');
 quit;
 
/* Count the number of unique values of SUBJECT. */                                                                                     
/* Also create macro variables containing the    */                                                                                     
/* style values for each plot line.  The line    */                                                                                     
/* color is based on the visit.        */                                                                                     
data total_dup1;    
length color $5.; 
   set pro end=eof;                                                                                                                      
   by d_SUBJID;   
      if d_VISITN=1 then color='vibg';
      if d_VISITN=2 then color='red';
	  if d_VISITN=3 then color='black';
      if d_VISITN=4 then color='depk';  
   if first.d_SUBJID then do;                                                                                                                   
      count+1;  
      call symput('gd'||trim(left(count)),                                                                                                
                  'style '|| 'GraphData' || trim(left(count)) ||                                                                          
                  ' from GraphData' || trim(left(count)) ||                                                                               
                  ' / ContrastColor=' || trim(left(color)) ||                                                                             
                  ' linestyle=1;');                                                                                                       
   end;                                                                                                                                  
   if eof then call symput('total',count);                                                                                               
run;                                                                                                                                    
                                                                                                                                        
/* Define a macro that generates all style changes. */                                                                                    
%macro gdata;                                                                                                                           
   %do i=1 %to &total;                                                                                                                   
      &&gd&i                                                                                                                              
   %end;                                                                                                                                 
%mend gdata;                                                                                                                            
                                                                                                                                        
/* Create the custom style. */                                                                                                          
proc template;                                                                                                                          
   define style styles.mystyle;                                                                                                          
   parent=styles.default;                                                                                                                
      %gdata;                                                                                                                               
   end;                                                                                                                                    
run;   

/*formatting the values to get the desred lenged values*/
proc format;
value visit
1 = 'Baseline'
2 = 'Timepoint 2'
3 = 'Timepoint 3'
4 = 'Timepoint 4';
run;

ods rtf file='C:\Users\ravindra.babu\OneDrive - OneWorkplace\Projs\NO8072A - RP PRO\NO8072A_F2_1_v_01.rtf'                                                   
style=rtf bodytitle nogfootnote;
goptions reset=all;
ods graphics / border=off width=18cm height=8cm ;
ods graphics / border=off width=17cm height=8.5cm; 
                                                                                                                     
/*ods rtf file='C:\Users\ravindra.babu\OneDrive - OneWorkplace\Projs\NO8072A - RP PRO\NO8072A_F2_1_v_01.rtf'  style=styles.mystyle;                                                   */
                                                                                                                                     
proc sgplot data=total_dup1 noautolegend;                                                                                                      
   series x=d_VISITN y=d_VPD5_Tot / group=d_SUBJID grouplc=count;                                                                                              
   xaxis label="Visit" values=(1 to 4 by 1);                                                                                       
   yaxis label="Total" values=(0 to 5 by 1); 
   format  d_VISITN visit.;
   title "Figure 2.1. Individual patients ViSIO-PRO total score at each visit (PRO treated analysis population, N=5)";                                                                                             
                                                                                                                                        
/* Use a FOOTNOTE statement to simulate a legend. */                                                                                    
   footnote1 box=1 bcolor=white                                                                                                            
             'Note: The PRO Treated Analysis Population are adult and adolescent patients who have received Luxturna treatment with at least one item completed on the ViSIO-PRO at one pre-Luxturna treatment timepoint (baseline) and at least one item completed on the ViSIO-PRO at one post-Luxturna treatment follow-up timepoint. ViSIO-PRO total score ranges from 0 to 5 with higher scores indicating worse visual functioning or HRQoL.'  ;                                                                                                         
                                                                                                                                     
run;    
quit; 

ods rtf close;

The above is my code, i dont know where i am doing wrong, the graphs doesn't give different colors for each line all i get is the same colour but the legend appears to be in different colour, can someone help me please to get different colours for different lines.

1 ACCEPTED SOLUTION

Accepted Solutions
Ravindra_
Quartz | Level 8

hello, thank you for the response, i had tried using the options that you had suggested, please correct me where i am doing wrong in the below code, the output seems to have only one single color.

ods rtf file='C:\Users\ravindra.babu\OneDrive - OneWorkplace\Projs\NO8072A - RP PRO\NO8072A_F2_2_v_01.rtf'                                                   
style=festival ;
ods graphics / border=off width=18cm height=8cm ;
ods graphics / border=off width=17cm height=8.5cm; 


/* Create the graph. */                                                                                                                 
proc sgplot data=total_dup ;  
styleattrs datacontrastcolors=(red green black orange blue); 
   series x=d_VISITN y=total / group=d_SUBJID    grouplc=domain_score name=grouping;                                                                                              
   xaxis label="Visit" values=(1 to 4 by 1);                                                                                       
   yaxis label="Total" values=(0 to 5 by 1); 
   keylegend 'grouping'/type=linecolor noborder;
   format  d_VISITN visit. domain_score $score.;
   title "Figure 2.2. Spaghetti plot of ViSIO-PRO domain scores (PRO treated analysis population, N=5)";                                                                                             
                                                                                                                                        
/* Use a FOOTNOTE statement to simulate a legend. */                                                                                    
/*   footnote1 box=0 bcolor=white                                                                                                            */
          footnote1   'Note: The PRO Treated Analysis Population are adult and adolescent patients who have 
                       received Luxturna treatment with at least one item completed on the ViSIO-PRO 
                       at one pre-Luxturna treatment timepoint (baseline) and at least one item 
completed on the ViSIO-PRO at one post-Luxturna treatment follow-up timepoint. ViSIO-PRO domain 
scores ranges from 0 to 5 with higher scores indicating worse visual functioning or HRQoL.'  ;   
                                                                                                                                     
run;  

ods rtf close;

View solution in original post

3 REPLIES 3
ballardw
Super User

If you go through all that rigamarole with macro variables and style elements I suggest that you look up the DATTRMAP= option for adding specific controls to a graph instead of creating and recreating a style whose contents you may not actually know at any given time.

 

I am not sure why you use the GROUPLC= COUNT option to control line color when you have a number of lines of code assigning values to a variable named COLOR that contains color values. But those were set according to values of your Xaxis variable, so don't make much sense either.

 

Hint: Provide data in the form of a datastep so we can test code.

Suggestion: Use a different different style than RTF such as MEADOW or FESTIVAL that have different color schemes. Since your code for SGPLOT shows the option NOAUTOLEGEND your comment about legends doesn't make sense or does not apply to the code shown.

 

Instead of creating a style or creating a dattrmap data set (useful for multiple graphs where you want things consistent ) perhaps just a STYLEATTRS(Datacontrastcolors)=(list of colors to use); would be simpler than creating a style.

Ravindra_
Quartz | Level 8

hello, thank you for the response, i had tried using the options that you had suggested, please correct me where i am doing wrong in the below code, the output seems to have only one single color.

ods rtf file='C:\Users\ravindra.babu\OneDrive - OneWorkplace\Projs\NO8072A - RP PRO\NO8072A_F2_2_v_01.rtf'                                                   
style=festival ;
ods graphics / border=off width=18cm height=8cm ;
ods graphics / border=off width=17cm height=8.5cm; 


/* Create the graph. */                                                                                                                 
proc sgplot data=total_dup ;  
styleattrs datacontrastcolors=(red green black orange blue); 
   series x=d_VISITN y=total / group=d_SUBJID    grouplc=domain_score name=grouping;                                                                                              
   xaxis label="Visit" values=(1 to 4 by 1);                                                                                       
   yaxis label="Total" values=(0 to 5 by 1); 
   keylegend 'grouping'/type=linecolor noborder;
   format  d_VISITN visit. domain_score $score.;
   title "Figure 2.2. Spaghetti plot of ViSIO-PRO domain scores (PRO treated analysis population, N=5)";                                                                                             
                                                                                                                                        
/* Use a FOOTNOTE statement to simulate a legend. */                                                                                    
/*   footnote1 box=0 bcolor=white                                                                                                            */
          footnote1   'Note: The PRO Treated Analysis Population are adult and adolescent patients who have 
                       received Luxturna treatment with at least one item completed on the ViSIO-PRO 
                       at one pre-Luxturna treatment timepoint (baseline) and at least one item 
completed on the ViSIO-PRO at one post-Luxturna treatment follow-up timepoint. ViSIO-PRO domain 
scores ranges from 0 to 5 with higher scores indicating worse visual functioning or HRQoL.'  ;   
                                                                                                                                     
run;  

ods rtf close;
ballardw
Super User

Without data there is no way to tell what you may be "doing wrong".

Either provide some example data in the form of data step code or rewrite your code to use a data set in the SASHELP library.

 

A typical approach to determining which of your options are not playing well with your graph is to start with very sparse code. Then add one feature/option at a time.

For instance start with

proc sgplot data=total_dup ;  

   series x=d_VISITN y=total / group=d_SUBJID   
  ;                                                                                              
   xaxis label="Visit" values=(1 to 4 by 1);                                                                                       
   yaxis label="Total" values=(0 to 5 by 1); 
   format  d_VISITN visit. domain_score $score.;
run;

Then start adding ONE option at a time.

 

If you only have one color in the output then there are some possible issues related to data such as only one value of your group variable has values for the x and y variables in the ranges supplied on the XAXIS and YAXIS values= options.

Another possible is there is only one value for the group=variable.

Which is why we ask for example data.

 

Note that since the Styleattrs(datacontrastcolors)= option and the Grouplc= option are attempting to set colors for the same objects, the lines, when they conflict the results are unpredictable and especially without any actual data.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1024 views
  • 0 likes
  • 2 in conversation