Hi All,
I have a dataset with two groups (treatment and control), and each patient has two timepoints (timepoint1 and timepoint2), I want draw a figure using Age and result like below with SAS 9.4. Anyone can give me some clue or example similar with this?
The x-axis is Age and y-asix is Result, both are continuous variable.
I want different color with different groups, different signs with different timepoints.
Thanks so much,
C
Further details: Use PROC TRANSPOSE or the DATA step to convert the data from long to wide format. Then you can use the VECTOR statement.
data have;
length Group $4.;
input Group ID Age TimePoint Result;
datalines;
TX 14468 15.8 1 75.74532
TX 14468 17 2 57.56404
TX 15597 15.1 1 62.84454
TX 15597 16.1 2 61.26036
TX 21016 9.2 1 40.1348
TX 21016 10.3 2 40.7989
TX 21834 11.1 1 34.01227
TX 21834 12 2 35.61295
TX 21838 13.6 1 46.02287
TX 21838 14.7 2 43.08785
TX 22596 16.1 1 50.71742
cont 24089 11.1 1 72.16842
cont 24089 12.1 2 45.67053
cont 24336 12.8 1 46.03624
cont 24336 13.8 2 50.30168
cont 25996 16.6 1 80.43335
cont 25996 17.6 2 77.73658
cont 26438 8.7 1 56.22557
cont 26438 9.7 2 33.98369
;
data want;
retain t1 t2 age1 age2 result1;
set have;
if TimePoint=1 then do;
t1 = Result;
age1 = age;
end;
else do;
t2 = Result;
age2 = age;
output;
end;
run;
proc sgplot data=want;
vector x=age2 y=t2 / xorigin=age1 yorigin=t1 group=Group;
xaxis label=age;
yaxis label=Result;
run;
Here's a basic two vector example similar to what you want:
data example; input gr $ xstart ystart xend yend; datalines; a 23 18 33 24 b 10 29 16 44 ; run; proc sgplot data=example; vector x=xend y=yend/ xorigin=xstart yorigin=ystart group=gr ; run;
Lots of options for appearance, you may want arrowdirection=both and arrowheadshape=filled (or maybe barbed) .
The key will be getting both x,y paired variables in one record. Not sure about the time point bit though. Perhaps you may need to have separte x,y variables for the different groups and use overlayed (multiple vector statements) to get different appearances.
Hi All,
I have a dataset, and want to test the relationship between age and result. but my goal is draw a figure like the attachment file. I tried to proc gplot and Spaghetti Plots (http://blogs.sas.com/content/graphicallyspeaking/2014/08/12/creating-spaghetti-plots-just-got-easy/) but found I am wrong. Any one have experience with figures like my goal?...... Even no idea how to start....
Group | ID | Age | TimePoint | Result |
TX | 14468 | 15.8 | 1 | 75.74532 |
TX | 14468 | 17 | 2 | 57.56404 |
TX | 15597 | 15.1 | 1 | 62.84454 |
TX | 15597 | 16.1 | 2 | 61.26036 |
TX | 21016 | 9.2 | 1 | 40.1348 |
TX | 21016 | 10.3 | 2 | 40.7989 |
TX | 21834 | 11.1 | 1 | 34.01227 |
TX | 21834 | 12 | 2 | 35.61295 |
TX | 21838 | 13.6 | 1 | 46.02287 |
TX | 21838 | 14.7 | 2 | 43.08785 |
TX | 22596 | 16.1 | 1 | 50.71742 |
cont | 24089 | 11.1 | 1 | 72.16842 |
cont | 24089 | 12.1 | 2 | 45.67053 |
cont | 24336 | 12.8 | 1 | 46.03624 |
cont | 24336 | 13.8 | 2 | 50.30168 |
cont | 25996 | 16.6 | 1 | 80.43335 |
cont | 25996 | 17.6 | 2 | 77.73658 |
cont | 26438 | 8.7 | 1 | 56.22557 |
cont | 26438 | 9.7 | 2 | 33.98369 |
Yes, you can use the VECTOR statement. An example is shown in a blog post about connecting a point to its nearest neighbor..
Further details: Use PROC TRANSPOSE or the DATA step to convert the data from long to wide format. Then you can use the VECTOR statement.
data have;
length Group $4.;
input Group ID Age TimePoint Result;
datalines;
TX 14468 15.8 1 75.74532
TX 14468 17 2 57.56404
TX 15597 15.1 1 62.84454
TX 15597 16.1 2 61.26036
TX 21016 9.2 1 40.1348
TX 21016 10.3 2 40.7989
TX 21834 11.1 1 34.01227
TX 21834 12 2 35.61295
TX 21838 13.6 1 46.02287
TX 21838 14.7 2 43.08785
TX 22596 16.1 1 50.71742
cont 24089 11.1 1 72.16842
cont 24089 12.1 2 45.67053
cont 24336 12.8 1 46.03624
cont 24336 13.8 2 50.30168
cont 25996 16.6 1 80.43335
cont 25996 17.6 2 77.73658
cont 26438 8.7 1 56.22557
cont 26438 9.7 2 33.98369
;
data want;
retain t1 t2 age1 age2 result1;
set have;
if TimePoint=1 then do;
t1 = Result;
age1 = age;
end;
else do;
t2 = Result;
age2 = age;
output;
end;
run;
proc sgplot data=want;
vector x=age2 y=t2 / xorigin=age1 yorigin=t1 group=Group;
xaxis label=age;
yaxis label=Result;
run;
Thanks so much, Rick. That works!!!!
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.