Hello,
I am trying to create a graph where the x axis will be time CD4 count was measured (before diagnosis, at diagnosis, 2 months after diagnosis, 4 month after diagnosis, 8 months after diagnosis and 10 months after diagnosis) and y axis will be the CD4 count. I want to label the grid values so that I can see: "before diagnosis", "2 months", "4 months" and so on on the x-axis. The partial code I want to use is below. How do I achieve the formatting of the "Time of CD4 measurement" values in the graph?
proc sgplot data=one;
panelby state;
refline 0/ axis=x lineattrs=(color= red pattern=2);
series x=time y=CD4_count lineattrs=(color=gray pattern=1 thickness=1);
colaxis label= "Time of CD4 measurement" grid values= (0 to 10 by 1);
rowaxis label= "CD4_count"; run;
I appreciate any help you can offer
A user defined format works fine.
Assuming you had used numbers instead:
proc format;
value time_measure_fmt
1 = 'Before'
2 = 'At'
3 = 'After';
run;
Then apply it in SGPLOT
format time time_measure_fmt.;
@lousam wrote:
Hello,
I am trying to create a graph where the x axis will be time CD4 count was measured (before diagnosis, at diagnosis, 2 months after diagnosis, 4 month after diagnosis, 8 months after diagnosis and 10 months after diagnosis) and y axis will be the CD4 count. I want to label the grid values so that I can see: "before diagnosis", "2 months", "4 months" and so on on the x-axis. The partial code I want to use is below. How do I achieve the formatting of the "Time of CD4 measurement" values in the graph?
proc sgplot data=one;
panelby state;
refline 0/ axis=x lineattrs=(color= red pattern=2);
series x=time y=CD4_count lineattrs=(color=gray pattern=1 thickness=1);
colaxis label= "Time of CD4 measurement" grid values= (0 to 10 by 1);
rowaxis label= "CD4_count"; run;
I appreciate any help you can offer
A user defined format works fine.
Assuming you had used numbers instead:
proc format;
value time_measure_fmt
1 = 'Before'
2 = 'At'
3 = 'After';
run;
Then apply it in SGPLOT
format time time_measure_fmt.;
@lousam wrote:
Hello,
I am trying to create a graph where the x axis will be time CD4 count was measured (before diagnosis, at diagnosis, 2 months after diagnosis, 4 month after diagnosis, 8 months after diagnosis and 10 months after diagnosis) and y axis will be the CD4 count. I want to label the grid values so that I can see: "before diagnosis", "2 months", "4 months" and so on on the x-axis. The partial code I want to use is below. How do I achieve the formatting of the "Time of CD4 measurement" values in the graph?
proc sgplot data=one;
panelby state;
refline 0/ axis=x lineattrs=(color= red pattern=2);
series x=time y=CD4_count lineattrs=(color=gray pattern=1 thickness=1);
colaxis label= "Time of CD4 measurement" grid values= (0 to 10 by 1);
rowaxis label= "CD4_count"; run;
I appreciate any help you can offer
Thank you. Sorry, I made a mistake I meant to use procsgpanel in my question. I am using a macro where my data set varies (4 data sets total) but the variables and the code remains the same as the one I listed in the previous question. For some reason using the format statement isn't working (can't see the formatted time values). Thank you again
1) don't see a FORMAT statement in the Proc SGPLOT/ SGPANEL code.
If the format is not permanently associated with the variable you need a statement such as
Format time <formatname.>;
2) We would likely need to see actual values of X and your format definition to diagnose anything further.
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.