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

I'm trying to plot some results from a survey using bar chart for each question. There are some questions that the participants skip answering, so the data would have -99 for the response on these skipped questions. How can I label this response globally (i.e. missing response) to the bar charts for each question?

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Without any data or code it is a bit difficult to be sure that a method works.

 

My first instinct is provide a custom format if you actually want to display that value.

Something like:

Proc format;
value mymiss
-99='Not answered'
;

Then assign that format in the procedure to the variable(s) that you want display "Not answered" , or your other preferred text.

The statement in the procedure would look like:

Format somevar mymiss. ;

I you haven't assigned formats before a single format statement can assign the same format to multiple variables.

Format thisvar thatvar var1-var25 mymiss. ;

would assign the format to 27 variables(if they exist and are of the correct type).

 

If you want this a default appearance all the time then you make it the default format for the intended variables. This might be done when reading or modifying the data set values or use Proc Datasets to change the default format for all the variables.

 

Caveats: Since this is not SAS supplied format you need to make sure it is available in each session one way or another. If the variable has some other custom format already assigned there might be a collision of results and other values may not behave as intended. The above format assumes the values are numeric. If you have character valued variables then the name on the value statement would $mymiss. If you have both character and numeric values that need this treatment then you need both a character and numeric version and assign the correct one to the variables.

Order of appearance may get complicated depending on where you want that value to appear in the graph.

 

I won't address order of appearance issues without actual data and program code.

 

I suggest that you keep the text for the formatted value short as graphs often have space limitations that long text can complicate.

 

One of the nice things about formats is that you can change them on the fly for specific reports, graphs or analysis just by using a different format statement in that one procedure.

 

 

View solution in original post

2 REPLIES 2
ballardw
Super User

Without any data or code it is a bit difficult to be sure that a method works.

 

My first instinct is provide a custom format if you actually want to display that value.

Something like:

Proc format;
value mymiss
-99='Not answered'
;

Then assign that format in the procedure to the variable(s) that you want display "Not answered" , or your other preferred text.

The statement in the procedure would look like:

Format somevar mymiss. ;

I you haven't assigned formats before a single format statement can assign the same format to multiple variables.

Format thisvar thatvar var1-var25 mymiss. ;

would assign the format to 27 variables(if they exist and are of the correct type).

 

If you want this a default appearance all the time then you make it the default format for the intended variables. This might be done when reading or modifying the data set values or use Proc Datasets to change the default format for all the variables.

 

Caveats: Since this is not SAS supplied format you need to make sure it is available in each session one way or another. If the variable has some other custom format already assigned there might be a collision of results and other values may not behave as intended. The above format assumes the values are numeric. If you have character valued variables then the name on the value statement would $mymiss. If you have both character and numeric values that need this treatment then you need both a character and numeric version and assign the correct one to the variables.

Order of appearance may get complicated depending on where you want that value to appear in the graph.

 

I won't address order of appearance issues without actual data and program code.

 

I suggest that you keep the text for the formatted value short as graphs often have space limitations that long text can complicate.

 

One of the nice things about formats is that you can change them on the fly for specific reports, graphs or analysis just by using a different format statement in that one procedure.

 

 

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 382 views
  • 2 likes
  • 2 in conversation