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:
my dataset and graph is below
/*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;
I think you also need GROUPDISPLAY=CLUSTER to get the look you want in the plot.
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 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.
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:
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;
@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.
I think you also need GROUPDISPLAY=CLUSTER to get the look you want in the plot.
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
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;
@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.
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!
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.
Ready to level-up your skills? Choose your own adventure.