Hi all,
My goal is to produce several parameter-by-age series for each ID and have several reference percentiles on the same plot. Reference percentiles' data are provided for the age range of 24-240:
Age (in months) | 3rd Percentile BMI Value | 5th Percentile BMI Value | 10th Percentile BMI Value | 25th Percentile BMI Value | 50th Percentile BMI Value | 75th Percentile BMI Value | 85th Percentile BMI Value | 90th Percentile BMI Value | 95th Percentile BMI Value | 97th Percentile BMI Value |
24 | 14.52095 | 14.73732 | 15.09033 | 15.74164 | 16.57503 | 17.55719 | 18.16219 | 18.60948 | 19.33801 | 19.85986 |
24.5 | 14.50348 | 14.71929 | 15.07117 | 15.71963 | 16.54777 | 17.52129 | 18.11955 | 18.56111 | 19.2789 | 19.79194 |
25.5 | 14.46882 | 14.68361 | 15.03336 | 15.67634 | 16.49443 | 17.45135 | 18.03668 | 18.4673 | 19.16466 | 19.66102 |
... | ... | ... | ... | ... | ... | ... | ... | ... |
The actual data is much narrower by the age and also very scarce in datapoints for each ID. They have to be on the same dataset, so both setting and merging them together were tested, but desired output can't be achieved either way using SGPLOT. What is the key to have these series be plotted correctly?
Current code:
PROC SGPLOT DATA = plotdata;
styleattrs datacontrastcolors=('red' 'green' 'blue' 'black' 'maroon');
SCATTER Y=chaaval X=ageass / MARKERATTRS = (SYMBOL=circlefilled size=5px color="GREEN") legendlabel='Group 1' name='cohorta' ;
SERIES Y=chaaval X=ageass / group=USUBJID datalabel=subjnum LINEATTRS = (THICKNESS = 2.25 COLOR="GREEN" PATTERN = Solid) legendlabel='Group 1' name="linea";
SCATTER Y=chbaval X=ageass / MARKERATTRS = (SYMBOL=circlefilled size=5px color="RED") legendlabel='Group 2' name='cohortb' ;
SERIES Y=chbaval X=ageass / group=USUBJID datalabel=subjnum LINEATTRS = (THICKNESS = 2.25 COLOR="RED" PATTERN = Solid) legendlabel='Group 2' name="lineb";
SERIES Y = _3RD_PERCENTILE_VALUE X = agem_htab / LINEATTRS = (THICKNESS = 1 COLOR=gray PATTERN = Solid) curvelabel='3rd percentile' CURVELABELATTRS=(SIZE = 5 COLOR=gray weight=NORMAL) CURVELABELLOC=OUTSIDE;
SERIES Y = _5TH_PERCENTILE_VALUE X = agem_htab / LINEATTRS = (THICKNESS = 1 COLOR=gray PATTERN = Solid) curvelabel='5th percentile' CURVELABELATTRS=(SIZE = 5 COLOR=gray weight=NORMAL) CURVELABELLOC=OUTSIDE;
SERIES Y = _10TH_PERCENTILE_VALUE X = agem_htab / LINEATTRS = (THICKNESS = 1 COLOR=gray PATTERN = Solid) curvelabel='10th percentile' CURVELABELATTRS=(SIZE = 5 COLOR=gray weight=NORMAL) CURVELABELLOC=OUTSIDE;
SERIES Y = _25TH_PERCENTILE_VALUE X = agem_htab / LINEATTRS = (THICKNESS = 1 COLOR=gray PATTERN = Solid) curvelabel='25th percentile' CURVELABELATTRS=(SIZE = 5 COLOR=gray weight=NORMAL) CURVELABELLOC=OUTSIDE;
SERIES Y = _50TH_PERCENTILE_VALUE X = agem_htab / LINEATTRS = (THICKNESS = 1 COLOR=orange PATTERN = Solid) curvelabel='50th percentile' CURVELABELATTRS=(SIZE = 5 COLOR=gray weight=NORMAL) CURVELABELLOC=OUTSIDE;
SERIES Y = _75TH_PERCENTILE_VALUE X = agem_htab / LINEATTRS = (THICKNESS = 1 COLOR=gray PATTERN = Solid) curvelabel='75th percentile' CURVELABELATTRS=(SIZE = 5 COLOR=gray weight=NORMAL) CURVELABELLOC=OUTSIDE;
SERIES Y = _90TH_PERCENTILE_VALUE X = agem_htab / LINEATTRS = (THICKNESS = 1 COLOR=gray PATTERN = Solid) curvelabel='90th percentile' CURVELABELATTRS=(SIZE = 5 COLOR=gray weight=NORMAL) CURVELABELLOC=OUTSIDE;
SERIES Y = _95TH_PERCENTILE_VALUE X = agem_htab / LINEATTRS = (THICKNESS = 1 COLOR=gray PATTERN = Solid) curvelabel='95th percentile' CURVELABELATTRS=(SIZE = 5 COLOR=gray weight=NORMAL) CURVELABELLOC=OUTSIDE;
SERIES Y = _97TH_PERCENTILE_VALUE X = agem_htab / LINEATTRS = (THICKNESS = 1 COLOR=gray PATTERN = Solid) curvelabel='97th percentile' CURVELABELATTRS=(SIZE = 5 COLOR=gray weight=NORMAL) CURVELABELLOC=OUTSIDE;
REFLINE 15 20 25 30 35 49/LINEATTRS = (THICKNESS = 1 COLOR=gray PATTERN = Solid) transparency=.3;
XAXIS label="BMI at Visit (months)" values=(24 to 132 by 12);
YAXIS label= "BMI" values=(15 to 40 by 5);
KEYLEGEND 'cohorta' 'cohortb' /title="Group:" location=OUTSIDE position=bottom autoitemsize;
run;
Data example:
subjnum | AGEASS | chaaval | chbaval | AVAL | agem_htab |
1 | 99.876796715 | 17.6 | . | 17.6 | 99.5 |
2 | 68.73100616 | 16.4 | . | 16.4 | 68.5 |
2 | 73.659137577 | 16.9 | . | 16.9 | 73.5 |
3 | 87.260780287 | . | 19.3 | 19.3 | 86.5 |
3 | 91.86036961 | . | 19 | 19 | 91.5 |
4 | 72.542094456 | . | 19.2 | 19.2 | 72.5 |
5 | 56.509240246 | . | 16.7 | 16.7 | 56.5 |
Expected kind of plot:
How do we know what "series plotted correctly" would look like?
I am afraid that without actual working data step example data including some for the variables you show no values for such as Chaaval Chbaval Ageass Agem_htab
If USUBJID is individual identifier how many values are there? That has the possibility of making any graph next to useless if the number is excessive. With the number of different "series" plots you have that number might be excessive at a pretty small number.
The example "data" percentiles looks a bit like standard growth charts, is it? You may want to investigate the stuff at https://www.cdc.gov/nccdphp/dnpao/growthcharts/resources/sas.htm for what I think comes close.
Yes, that is a CDC growth chart.
The number of IDs that is expected on the plot is not too big, so it is not too cluttered.
Edited the post to include data example.
upd.: another edit to include desired output.
Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.
Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.
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.