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

HI 

I am trying to generate a sgplot line graph similar to the (reference graph) but unable to generate . any inputs will be apprecaited.

 

 

Thanks kindly!!!

reference graph:

 

reference_lineGRAPH.JPG

 

my dataset and graph is below

 

My_Linegraph.JPG

 

my_dataset.JPG

/*plot graph and save the graph in rtf file*/

goptions reset=all device=png;
*ods graphics / reset width=5in height=3in;
*ods rtf file="&graphdir\cy1234_001_lab_g.rtf";

Options nodate nonumber orientation=landscape;

Title1 j=c h=1.5 f="Times new roman" "% Change (Mean+/-SE) from Baseline for CY-1234-001";

Title2 j=c h=1.5 f="Times new roman" "Summary for Laboratory test : Nagtotal";

Proc sgplot Data=lb_jittering;

 SERIES X= avisit y= trtpn / LEGENDLABEL =    'Placebo'
    MARKERS LINEATTRS = (pattern= solid THICKNESS = 1)
      MARKERATTRS= (color=black symbol=circle);

 SERIES X = avisit Y = YAXIS / LEGENDLABEL = 'CY-001 10 mg'
    MARKERS LINEATTRS = (PATTERN=SHORTDASH  THICKNESS = 1)
        MARKERATTRS= (color=black symbol=trianglefilled);

 SERIES X = avisit Y = X_AXIS / LEGENDLABEL = 'CY-001 50 mg'
    MARKERS LINEATTRS = (PATTERN=LONGDASH THICKNESS = 1)
     MARKERATTRS= (color=black symbol=squarefilled);

 SERIES X = avisit Y = Y_AXIS / LEGENDLABEL =  'CY-001 100 mg'
    MARKERS LINEATTRS = (PATTERN=DOT THICKNESS = 1)
     MARKERATTRS= (color=black symbol=diamondfilled);

 XAXIS TYPE = DISCRETE; 
         
xaxis label = "Weeks on Treatment";

yaxis integer values=(-20 to 50 by 10)
           label= "% Change from Baseline(Mean+/-SE)";

refline 0; 


run;

quit;
title;
*ods rtf close;
1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

I think you also need GROUPDISPLAY=CLUSTER to get the look you want in the plot.

View solution in original post

9 REPLIES 9
Ksharp
Super User

How about this one ?

 

data class;
 set sashelp.class;
run;
proc sort data=class nodupkey;by age;run;

proc sgplot data=class;
series x=name y=weight/markers discreteoffset=0.5 markerattrs=(symbol=circlefilled);
series x=name y=age/markers discreteoffset=0.2 markerattrs=(symbol=squarefilled);
series x=name y=height/markers discreteoffset=0 markerattrs=(symbol=starfilled);
run;

azhar7860
Obsidian | Level 7
Thanks for the info.

You used 3 different variable for y axis.
I have a variable TRTP(TRTPN) Which has 4 sub groups . and i am trying to
get their corresponding values like displayed in reference line graph.

Your response will be appreciated.

Thanks Kindly

Azhar.

ballardw
Super User

@azhar7860 wrote:
Thanks for the info.

You used 3 different variable for y axis.
I have a variable TRTP(TRTPN) Which has 4 sub groups . and i am trying to
get their corresponding values like displayed in reference line graph.

Your response will be appreciated.

Thanks Kindly

Azhar.


Since your code showed 4 different y axis variables I am not sure what you actually mean here.

If you want to display values based on the levels of another variable then use a GROUP= option on the plot.

 

You need to describe for the "want" graph: what the single marker represents, what the "whiskers" actually represent

 

And a picture is not data. We cannot write code to make a graph from a picture of data.

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

azhar7860
Obsidian | Level 7

Thanks for the solution. I use the group option and i am pretty close to my reference graph.

How can i change the line and markers attributes for each subgroup as seen in reference line graph below

Thanks Kindly!

 

My new  output:

 

Mynew_output.JPG

 

reference_lineGRAPH.JPG

 

 

My new code:

/*plot graph and save the graph in rtf file*/

goptions reset=all device=png;
*ods graphics / reset width=5in height=3in;
*ods rtf file="&graphdir\cy1234_001_lab_g.rtf";

Options nodate nonumber orientation=landscape;

Title1 j=c h=1.5 f="Times new roman" "% Change (Mean+/-SE) from Baseline for CY-1234-001";

Title2 j=c h=1.5 f="Times new roman" "Summary for Laboratory test : Nagtotal";

Proc sgplot Data=lb_jittering;

 Series X= avisit y= y_axis / group=trtp;

 XAXIS TYPE = DISCRETE; 
         
xaxis label = "Weeks on Treatment";

yaxis integer values=(-20 to 50 by 10)
           label= "% Change from Baseline(Mean+/-SE)";

refline 0; 


run;

quit;
title;
*ods rtf close;



ballardw
Super User
@azhar7860 wrote:

Thanks for the solution. I use the group option and i am pretty close to my reference graph.

How can i change the line and markers attributes for each subgroup as seen in reference line graph below

Thanks Kindly!

 

 


You could add a STYLEATTRS statement:

 

styleattrs  datacontrastcolors= (red blue green pink)

                 datalinepatterns = (solid shortdash longdash dot)

                 datasymbols = ( circlefilled diamondfilled squarefilled trianglefilled)

;

for example would have the first line and marker as red, solid and show a circlefilled for the marker). check the documentation for the different line pattern and marker options.

 

Another approach is a DATTRMAP with which can contain a host of description options including text controls and such which may be more flexible in the long run if you do many similar graphs as then you indicate the name of the data set on the Proc Statement and then in the specific plot use the ATTRID= name, where name is one of the sets of rules for displaying a GROUP variable.

 

DanH_sas
SAS Super FREQ

I think you also need GROUPDISPLAY=CLUSTER to get the look you want in the plot.

azhar7860
Obsidian | Level 7

Thanks for the input. I amended the code but somehow the datasymbols option is not working, i will check the resources you mentioned.

my new output

 

new_output.JPG

 

 

My amended code

/*plot graph and save the graph in rtf file*/

goptions reset=all device=png;
*ods graphics / reset width=5in height=3in;
*ods rtf file="&graphdir\cy1234_001_lab_g.rtf";

Options nodate nonumber orientation=landscape;

Title1 j=c h=1.5 f="Times new roman" "% Change (Mean+/-SE) from Baseline for CY-1234-001";

Title2 j=c h=1.5 f="Times new roman" "Summary for Laboratory test : Nagtotal";

Proc sgplot Data=lb_jittering;

 Series X= avisit y= y_axis / group=trtp GROUPDISPLAY=CLUSTER;
 styleattrs  datacontrastcolors= (grey)                                           /*(red blue green pink)*/                

                 datalinepatterns = (solid shortdash longdash dot)

                 datasymbols = ( circle trianglefilled  squarefilled  diamondfilled);

 XAXIS TYPE = DISCRETE; 
         
xaxis label = "Weeks on Treatment";

yaxis integer values=(-20 to 50 by 10)
           label= "% Change from Baseline(Mean+/-SE)";

refline 0; 


run;

quit;
title;
*ods rtf close;
ballardw
Super User

@azhar7860 wrote:

Thanks for the input. I amended the code but somehow the datasymbols option is not working, i will check the resources you mentioned.

my new output

 

 

 

 

 


You have to add the MARKERS option on the Series plot to display markers.

azhar7860
Obsidian | Level 7
Thanks a lot!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 9 replies
  • 1338 views
  • 4 likes
  • 4 in conversation