Hi,
I'm a begginer at sas graph programming and I need to create a line graph with xaxis that shows patient visits and yaxis that show lab test results. Visit consits of 1st,8th and 15th visit and for one patient visit=end of treatment (EOT). I need to present this EOT at the end of xaxis as a dot and not connected to line graph.
my code
proc sgplot data=lb;
series x=vis y=result / group=usubjid grouplc=armcd break
transparency=0.7 lineattrs=(pattern=solid);
xaxis label="Timepoint" ;
Yaxis values=(0 to 30 by 2) label="arm";
keylegend / type=linecolor title="";
run;
@Jedrzej wrote:
scatter is good but the dot is connected to the graph line (probably because I use the same variable for x=vis).
when I create two separate variables for EOT (x and y) it is good but the dot appears at the begging of the graph and i want it at the end.
I missed that you want to set the original Y value to missing for the EOT observations. That happens when there is no data to actually test code against.
data example; input x y1 y2 gv; datalines; 1 1 . 1 2 2 . 1 3 3 . 1 4 . 4 1 1 2 . 2 2 3 . 2 3 4 . 2 4 . 6 2 ; proc sgplot data=example; series x=x y=y1/group=gv; scatter x=x y=y2 /group=gv markerattrs=(symbol=circlefilled); run;
Data is helpful.
Likely the easiest is to create another variable with the value you need for just that point, same xaxis variable with appropriate value, new y axis variable with the same range of values. Then use a SCATTER plot to overlay that on the series plot. You would not want your current Yaxis variable to have that value anymore.
The code would look something like:
proc sgplot data= NEWPLOTDATASET ; series x=vis y=result / group=usubjid grouplc=armcd break transparency=0.7 lineattrs=(pattern=solid); scatter x=vis y=EOTvariable/ group=usubjid markerattrs=(symbol=circlefilled) ; xaxis label="Timepoint" ; Yaxis values=(0 to 30 by 2) label="arm"; keylegend / type=linecolor title=""; run;
There are options in the Markerattrs to control size if the defaults are too big or small. You may want the JITTER option on the SCATTER if the scatter "dots" overlap or hide each other because of similar values. That will make small adjustments from the actual x,y values so the symbols appear slightly apart.
@Jedrzej wrote:
scatter is good but the dot is connected to the graph line (probably because I use the same variable for x=vis).
when I create two separate variables for EOT (x and y) it is good but the dot appears at the begging of the graph and i want it at the end.
I missed that you want to set the original Y value to missing for the EOT observations. That happens when there is no data to actually test code against.
data example; input x y1 y2 gv; datalines; 1 1 . 1 2 2 . 1 3 3 . 1 4 . 4 1 1 2 . 2 2 3 . 2 3 4 . 2 4 . 6 2 ; proc sgplot data=example; series x=x y=y1/group=gv; scatter x=x y=y2 /group=gv markerattrs=(symbol=circlefilled); run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.