BookmarkSubscribeRSS Feed
GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

Using SAS 9.4

I am running the following code:

 

proc format;
value $ funcfmt "X"="A-Severly Abnormal"
"Abnormal"="B-Abnormal"
"Nearly normal"="C-Nearly normal"
"Normal"="D-Normal";
run;

proc summary data= peroneal.labeled nway completetypes;
class ratecurrent_level_func / preloadfmt order=formated missing;
format ratecurrent_level_func $funcfmt.;
output out=counts;
run;

overall current level of function;
options reset=all ;
ods graphics on /
imagefmt=tiff
imagename="Overall, Current Level of Function"
width=15cm
noborder;
ods listing gpath= "path" image_dpi=300 ;
proc sgplot data=counts;
format ratecurrent_level_func $funcfmt.;
title 'Overall, Current Level of Function';
vbarparm category=ratecurrent_level_func response=_FREQ_ / nozerobars;
yaxis grid label='Percent';
xaxis values=("Severly Abnormal" "Abormal" "Nearly Normal" "Normal");
run;

run;
ods graphics off;

 

I am trying to get a bar graph with the data in order from severly abnormal, abnormal, nearly normal and normal. So I used the format to get the data in that order; however, I do not want "A-", "B-" etc precedding the value name so I used the xaxis values. When I do this it distorts the graph? Does anyone know what I am doing incorrectly? I have attached a word document with an example of each graph. The first one is correct other than the labels are inaccurate and the second is what happens when I add the xaxis values statement. Thank you

8 REPLIES 8
PaigeMiller
Diamond | Level 26

I do not download attachments, as they can be a security threat. So please include your graph in your reply by clicking on the camera icon.

 

however, I do not want "A-", "B-" etc precedding the value name

 

Then don't put them in your format. If you are putting them there to force the proper order on the x-axis, then in PROC SGPLOT you can use the VALUES= option of the XAXIS statement. There is an example here: https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.4&docsetId=grstatproc&docsetTarget=p... (scroll down)

--
Paige Miller
GS2
Obsidian | Level 7 GS2
Obsidian | Level 7

SGPlot10.pngSGPlot11.png

 

The first is the correct version and my code will produce without the xaxis values statement. When I include xaxis value the second graph is produced

PaigeMiller
Diamond | Level 26

Please show us the LOG from your code, starting at PROC FORMAT and then all the way down to the NOTES after PROC SGPLOT. Do not chop anything out.

 

Follow these instructions exactly: Copy the log as text, then paste it into the window that appears when you click on the </> icon. DO NOT SKIP THIS STEP.

--
Paige Miller
GS2
Obsidian | Level 7 GS2
Obsidian | Level 7
64  proc format;
2465      value $ funcfmt "X"="A-Severly Abnormal"
2466                      "Abnormal"="B-Abnormal"
2467                     "Nearly normal"="C-Nearly normal"
2468                     "Normal"="D-Normal";
NOTE: Format $FUNCFMT is already on the library WORK.FORMATS.
NOTE: Format $FUNCFMT has been output.
2469  run;

NOTE: PROCEDURE FORMAT used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


2470
2471  proc summary data= peroneal.labeled nway completetypes;
2472     class ratecurrent_level_func / preloadfmt order=formated missing;
2473     format ratecurrent_level_func $funcfmt.;
2474     output out=counts;
2475  run;

NOTE: There were 51 observations read from the data set PERONEAL.LABELED.
NOTE: The data set WORK.COUNTS has 4 observations and 3 variables.
NOTE: PROCEDURE SUMMARY used (Total process time):
      real time           0.04 seconds
      cpu time            0.06 seconds


2476
2477  *overall current level of function;
2478  options reset=all ;
              -----
              13
ERROR 13-12: Unrecognized SAS option name RESET.
2479  ods graphics on /
2480  imagefmt=tiff
2481  imagename="Overall, Current Level of Function"
WARNING: The IMAGENAME option or the output name contains invalid characters. Overall_ Current
         Level of Function will be used as the image name prefix.
2482  width=15cm
2483  noborder;
2484  ods listing gpath= "C:\Users\gscar\Desktop\FA094 Peroneal Subluxation\Tables" image_dpi=300
2484! ;
2485  proc sgplot data=counts;
2486      format ratecurrent_level_func $funcfmt.;
2487      title 'Overall, Current Level of Function';
2488      vbarparm category=ratecurrent_level_func response=_FREQ_ / nozerobars;
2489      yaxis grid label='Percent';
2490      xaxis values=("Severly Abnormal" "Abormal" "Nearly Normal" "Normal");
2491  run;

NOTE: Writing HTML Body file: sashtml4.htm
NOTE: PROCEDURE SGPLOT used (Total process time):
      real time           0.83 seconds
      cpu time            0.50 seconds

WARNING: HTML4 destination does not support TIFF images. Using the default static format.
NOTE: Listing image output written to C:\Users\gscar\Desktop\FA094 Peroneal
      Subluxation\Tables\Overall_ Current Level of Function9.tiff.
NOTE: There were 4 observations read from the data set WORK.COUNTS.

2492  ods graphics off;











Log of the distorted graph above

 

Log of correct graph below

2493  proc format;
2494      value $ funcfmt "X"="A-Severly Abnormal"
2495                      "Abnormal"="B-Abnormal"
2496                     "Nearly normal"="C-Nearly normal"
2497                     "Normal"="D-Normal";
NOTE: Format $FUNCFMT is already on the library WORK.FORMATS.
NOTE: Format $FUNCFMT has been output.
2498  run;

NOTE: PROCEDURE FORMAT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


2499
2500  proc summary data= peroneal.labeled nway completetypes;
2501     class ratecurrent_level_func / preloadfmt order=formated missing;
2502     format ratecurrent_level_func $funcfmt.;
2503     output out=counts;
2504  run;

NOTE: There were 51 observations read from the data set PERONEAL.LABELED.
NOTE: The data set WORK.COUNTS has 4 observations and 3 variables.
NOTE: PROCEDURE SUMMARY used (Total process time):
      real time           0.05 seconds
      cpu time            0.06 seconds


2505
2506  *overall current level of function;
2507  options reset=all ;
              -----
              13
ERROR 13-12: Unrecognized SAS option name RESET.
2508  ods graphics on /
2509  imagefmt=tiff
2510  imagename="Overall, Current Level of Function"
WARNING: The IMAGENAME option or the output name contains invalid characters. Overall_ Current
         Level of Function will be used as the image name prefix.
2511  width=15cm
2512  noborder;
2513  ods listing gpath= "C:\Users\gscar\Desktop\FA094 Peroneal Subluxation\Tables" image_dpi=300
2513! ;
2514  proc sgplot data=counts;
2515      format ratecurrent_level_func $funcfmt.;
2516      title 'Overall, Current Level of Function';
2517      vbarparm category=ratecurrent_level_func response=_FREQ_ / nozerobars;
2518      yaxis grid label='Percent';
2519      *xaxis values=("Severly Abnormal" "Abormal" "Nearly Normal" "Normal");
2520  run;

NOTE: PROCEDURE SGPLOT used (Total process time):
      real time           0.23 seconds
      cpu time            0.09 seconds

WARNING: HTML4 destination does not support TIFF images. Using the default static format.
NOTE: Listing image output written to C:\Users\gscar\Desktop\FA094 Peroneal
      Subluxation\Tables\Overall_ Current Level of Function11.tiff.
NOTE: There were 4 observations read from the data set WORK.COUNTS.

2521  ods graphics off;
PaigeMiller
Diamond | Level 26

Eliminate the format. Do not apply it in PROC SUMMARY or anywhere else.

 

In PROC SGPLOT, use: 

 

xaxis values=("Severly Abnormal" "Abormal" "Nearly Normal" "Normal");

and make sure the spelling and capitalization in the XAXIS statement match exactly what is in your data set peroneal.labeled (there are at least two spelling errors and one place where the capitalization changes throughout your code, but the code must match the data)

 

--
Paige Miller
ballardw
Super User

Don't apply the format if you do not want that appearance, or create a different format without the A- B- C-.

 

 

Spelling counts: Look closely at your Values and see if you find a spelling problem with the second value.

Also from your format definition then there appears that you do not have a Value = "Severely Abnormal".

 

From the documentation of the Values option in the Xaxis statement:

   
If a custom format is applied to the value, the raw value is plotted first and then formatted.

Which means that the VALUES you list must be exactly as they appear in the data for character values.

 

 

 

 

GS2
Obsidian | Level 7 GS2
Obsidian | Level 7
That is correct. There is no value for 'severely abnormal' , I am trying to show a zero in that column and report the others but in a specific order.
PaigeMiller
Diamond | Level 26

@GS2 wrote:
That is correct. There is no value for 'severely abnormal' , I am trying to show a zero in that column and report the others but in a specific order.

You will need to use the PRELOADFMT option of the CLASS statement. Example: https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=proc&docsetTarget=n1eseau...

--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 8 replies
  • 1852 views
  • 0 likes
  • 3 in conversation