BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lousam
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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


 

View solution in original post

3 REPLIES 3
Reeza
Super User

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


 

lousam
Obsidian | Level 7

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

ballardw
Super User

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 7983 views
  • 0 likes
  • 3 in conversation