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


Hi ,

I created a histogram on a numeric variable which has 10 digts after the decimal point. I want that to be retained as I like the distribution of the values by the bars, but the numbers displayed on the x-axis should have only 2 digits after the decimal point. Is it possible to manipulate the format of the x -axis in proc univariate only ? My code is:

proc univariate data=test;

  var var1;

histograms /midpoints= 5.6703546745 to 35.9034765215 by 0.5;  /* assume the minimum value of var1 is 5.6703546745 and maximum value of var1 is 35.9034765215 */

run;

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

Can you attach a sample data set that will work with your program?  Then we can try ways ways to improve the graph? 

Do you care if the X axis has a simple linear tick values?  That usually works well in such cases, unless you absolutely need these long bin edge values on the x axis.  You can get that by using the Histogram statement in proc SGPLOT instead of proc UNIVARIATE.

View solution in original post

13 REPLIES 13
ballardw
Super User

I would try adding a statement: Format var1 f5.2;

By default my midpoints default to 2 decimals with data in a similar range.

dr2014
Quartz | Level 8

@ballardw...I don't want to change the format of var1 , because once you round up all the values they are very similar and I don't  get get a detailed graph. I just want to change the display of the major unit on the x-axis and round those values to the 2nd decimal point. I was looking through all options in proc univariate and I didn't come across any for the x- or horizontal axis as yet. Do you have any suggestions for me ? or is it just not possible with proc univariate ?

Jay54
Meteorite | Level 14

It is hard to see what is going on and make suggestions if you do not provide the full program with data.  Also provide the SAS release you are using.

dr2014
Quartz | Level 8

@Sanjay@SAS..I understand.  I am working on it and will post it soon.

dr2014
Quartz | Level 8

@ballardw and @Sanjay@SAS.....

I am using SAS 9.4. My present graph's x-axis looks like this. This is just an example. My original graph shows a nice bell shaped distribution as it has a lot of observations and the right intervals on the x-axis. Now ,I am only interested in displaying 2 digits after the decimal point on major unit on the horizontal axis . The reason being I have 1000 such observations and it gets too crowded on the x-axis. I do not wish to change the format of the var1 variable and round it to the 2nd decimal , because I then loose the details in the distribution of the data.

My code is generic as the input data set changes but the variable name is the same.

proc univariate data=a.&dataset. ;

  var var1;

     histogram/ midpoints=&var1_min to &var1_max by 0.5

              rtinclude;

run;

Jay54
Meteorite | Level 14

Can you attach a sample data set that will work with your program?  Then we can try ways ways to improve the graph? 

Do you care if the X axis has a simple linear tick values?  That usually works well in such cases, unless you absolutely need these long bin edge values on the x axis.  You can get that by using the Histogram statement in proc SGPLOT instead of proc UNIVARIATE.

ballardw
Super User

If I understand that

Format var1 f4.2; doesn't work then you have much more work in defining boundaries and then using a different procedure to plot the data using a different procedure.

You might be able to create a custom format from you macro variables such that you set the range and have the value displayed to the precision you want.

dr2014
Quartz | Level 8

I am trying to figure the same @ballardw but would like a simpler solution. @Sanjay@SAS and ballardw here is a better example of my graph and closely represents my original graph. Now since there are 100 observations on the x-axis...major unit values are represented upto 4 digits after the decimal point. Would doing this graph in sgplot give me better control on the x-axis major unit format? @Sanjay@SAS , this is the range of values in var1. Hope this helps. Thanks.

DanH_sas
SAS Super FREQ

As said, I would try using PROC SGPLOT. Use the BINSTART and BINWIDTH options on the HISTOGRAM statement to set up the midpoints as you did with UNIVARIATE. By default, the x-axis will display using a linear style axis. There is a BINAXIS option; but I agree with Sanjay that the linear axis will probably look a lot better.

dr2014
Quartz | Level 8

All right I will try proc sgplot, but before I do that...what do you mean by linear style axis ? Does it mean the major unit values will rounded up to a whole number ? I do need it by the 2nd decimal point though. If I remember, I shall be able to achieve that using sgplot.

DanH_sas
SAS Super FREQ

You can use the VALUES option on the XAXIS statement to specify the first, last and increment of the tick values you want. Also, specify the VALUESHINT so that the data range of the axis is not affected. Neither of these settings should affect the histogram midpoints.

Jay54
Meteorite | Level 14

By default, the axis tick values are placed at "rounded" values in the correct scaled location and marked as such.  So, for your case, the x axis tick values will likely be 4, 6, 8, 10 and so on, placed at the right location on the x axis.  You will only see the number of decimals that are needed.

The tick values will NOT necessarily line up with the bins.  See example below.  The first is UNIVARIATE, each bin has a value at its center.  The second is SGPLOT, where the x axis has rounded values evenly placed at the right location, but not necessarily at the center of each bin. The second can be useful with a large number of bins.

You can specify other tick values as you need as suggested by Dan.

Hist_Univariate.png

Hist_SGPlot.png

dr2014
Quartz | Level 8

Thank you Sanjay@SAS and DanH for your advice. I will get working on it now.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 13 replies
  • 9093 views
  • 9 likes
  • 4 in conversation