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

Hi, 

 

I am analyzing data of different strains with different genotypes and I am trying to format the x axis a certain way. My data is categorical and I would prefer not to change it numbers. I added a xaxis values statement and now my graph looks crazy. Any suggestions? I attached photos of before I used the xaxis value statement and after. Screen Shot 2021-04-23 at 1.32.59 PM.pngScreen Shot 2021-04-23 at 1.32.45 PM.pngThis is my code: 

 

*Creating figure plotting estiamted probs & CI**;

proc logistic data=estimated2 alpha=0.2 noprint;
class mosquitostrain (ref= 'NO') genotype / param=ref;
model Alive(Event='1')= mosquitostrain genotype;
/* 1. Use a procedure or DATA step to write Pred, Lower, and Upper limits */
output out=LogiOut predicted=estprob2 l=lower95 u=upper95;
run;
/* 2. Be sure to SORT! */
proc sort data=LogiOut;
by mosquitostrain genotype;
run;
/* 3. Use a BAND statement. If more that one band, use transparency */
title "Predicted Probabilities with 95% Confidence Limits";
title2 "Four Strains";
proc sgplot data=LogiOut;
band x=genotype lower=Lower95 upper=upper95 / group=mosquitostrain transparency=0.75;
series x=genotype y=estprob2 / group=mosquitostrain curvelabel;
xaxis grid;
xaxis values= ('WT,WT' 'WT,HET' 'HET,WT' 'HET,HET' 'MUT,WT' 'WT,MUT' 'HET,MUT' 'MUT,HET' 'MUT,MUT');
yaxis grid label="Predicted Probability of Survival" max=1;
keylegend "L" / location=inside position=NW title="Genotype" across=1 opaque;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Does a line chart make sense here at all?
How do I interpret the connection between HET/HET and HET/MUT? I would have assumed a forest plot was more appropriate. See examples at the link below

https://blogs.sas.com/content/tag/forest-plot/

 

Ignoring visualization choice, code your categories as numbers, ordered so that 1 is your first category and 2 is your second etc. 

Then graph it but apply a label to your X AXIS so that 1 will display as HET/HET and 2 will display as HET/MUT. 

 

You can use an informat to map the codes to numbers and then a format to map the numbers back to the data. 

 

Assuming your data now looks like this, use the code and apply a format instead with the FORMAT statement. 

https://support.sas.com/resources/papers/proceedings/proceedings/sugi30/001-30.pdf

GenoCode GenoType Probability UCLM LCLM
1 | HET,HET| 0.2| 0.07| 0.8
2 | HET,MUT| 0.2| 0.07| 0.8
3 | HET,WT| 0.2| 0.07| 0.8
title "Predicted Probabilities with 95% Confidence Limits";
title2 "Four Strains";
proc sgplot data=LogiOut;
band x=genocode lower=Lower95 upper=upper95 / group=mosquitostrain transparency=0.75;
series x=genocode y=estprob2 / group=mosquitostrain curvelabel;
xaxis grid;

format genocode genofmt.;

xaxis values= ('WT,WT' 'WT,HET' 'HET,WT' 'HET,HET' 'MUT,WT' 'WT,MUT' 'HET,MUT' 'MUT,HET' 'MUT,MUT');
yaxis grid label="Predicted Probability of Survival" max=1;
keylegend "L" / location=inside position=NW title="Genotype" across=1 opaque;
run;

 

 

View solution in original post

15 REPLIES 15
Madelyn_SAS
SAS Super FREQ

In which SAS product are you submitting your code? 

RaquelAR
Fluorite | Level 6
SAS 9.4
Reeza
Super User

Does a line chart make sense here at all?
How do I interpret the connection between HET/HET and HET/MUT? I would have assumed a forest plot was more appropriate. See examples at the link below

https://blogs.sas.com/content/tag/forest-plot/

 

Ignoring visualization choice, code your categories as numbers, ordered so that 1 is your first category and 2 is your second etc. 

Then graph it but apply a label to your X AXIS so that 1 will display as HET/HET and 2 will display as HET/MUT. 

 

You can use an informat to map the codes to numbers and then a format to map the numbers back to the data. 

 

Assuming your data now looks like this, use the code and apply a format instead with the FORMAT statement. 

https://support.sas.com/resources/papers/proceedings/proceedings/sugi30/001-30.pdf

GenoCode GenoType Probability UCLM LCLM
1 | HET,HET| 0.2| 0.07| 0.8
2 | HET,MUT| 0.2| 0.07| 0.8
3 | HET,WT| 0.2| 0.07| 0.8
title "Predicted Probabilities with 95% Confidence Limits";
title2 "Four Strains";
proc sgplot data=LogiOut;
band x=genocode lower=Lower95 upper=upper95 / group=mosquitostrain transparency=0.75;
series x=genocode y=estprob2 / group=mosquitostrain curvelabel;
xaxis grid;

format genocode genofmt.;

xaxis values= ('WT,WT' 'WT,HET' 'HET,WT' 'HET,HET' 'MUT,WT' 'WT,MUT' 'HET,MUT' 'MUT,HET' 'MUT,MUT');
yaxis grid label="Predicted Probability of Survival" max=1;
keylegend "L" / location=inside position=NW title="Genotype" across=1 opaque;
run;

 

 

Jay54
Meteorite | Level 14

Bands are drawn by creating polygons. This works best when the x coordinate increases monotonically.  That is what happens in the original data case, and you get good polygons.  When you reorder the x-axis values, the polygons no longer have monotonically increasing x values.  So you get self-intersecting polygons.

 

To get non-intersecting polygons, the data set should have the x-values in the same order as the x axis values you want.  Or, make the x axis linear (1-9) and use a UDF to label the values

Rick_SAS
SAS Super FREQ

As Reeza says, a format is the way to go. For an example, see "Method 2" in the article "Visualize an ANOVA with two-way interactions."

RaquelAR
Fluorite | Level 6
 
Reeza
Super User
Did you remember to change your data so that you have 1 to 5 in the data set? Show your full code, with partial code that refers to data we don't have accessible we can't replicate your issues.
RaquelAR
Fluorite | Level 6
Hello! I actually figured it out! I had to change my data set name! Thank you for all the help, once I changed the named of my data set I was able to use the proc format
RaquelAR
Fluorite | Level 6

Hi Reeza, 

Do you know if it is possible to use a proc format statement with proc logistic? I would also like to label the x axis the same way but using a graph created by proc logistic 

ods graphics on;
proc logistic data=Round3E plots(only)=(effect (clband) oddsratio (type=horizontalstat));
 class Genotype MosquitoStrain(param=ref ref="NO");
 model Alive (event="1") = Genotype MosquitoStrain/clodds=pl;
run;
ods graphics off; 
Reeza
Super User
Yes, try it 🙂
RaquelAR
Fluorite | Level 6

Hello, 

 

I tried this code and got this error message 

**trying another way to graph estimated prob & CI**;
ods graphics on;
proc logistic data=Round3E plots(only)=(effect (clband) oddsratio (type=horizontalstat));
 format Genotype $GenotFmt.;
 class Genotype MosquitoStrain(param=ref ref="NO")
ORDER='WT,WT' 'WT,HET' 'HET,WT' 'HET,HET' 'MUT,WT' 'WT,MUT' 'HET,MUT' 'MUT,HET' 'MUT,MUT';
 model Alive (event="1") = Genotype MosquitoStrain/clodds=pl;
run;
ods graphics off; 

Screen Shot 2021-04-26 at 11.20.30 AM.png

Reeza
Super User
The error is in your ORDER statement, remove that statement. Note that when you use the formatted option you shouldn't require the ORDER= in either of your solutions anymore. If you need further assistance at this point you're going to have to provide a fully worked example that lets us test your code. Or make up fake example data.
RaquelAR
Fluorite | Level 6

Hello, 

 

I deleted the order statement and it changed the variable labels but I would like to order them in a specific order (based on their genotype). 

 

 
Reeza
Super User
Then make sure when you code them, you map them to numbers in the order you want. SAS orders them alphabetically by default.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 15 replies
  • 3320 views
  • 5 likes
  • 5 in conversation