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

Hello,

 

I am currently trying to create a paneled vertical bar chart. Presently, the panel labels read: "State = Ohio", "State = Arizona", and "State = Colorado". However, I want the labels to read "St = Oh", "St = Ar", and "St = Co". Is there a statement that would allow me to change what the panel labels state. Thank you in advance!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

There are many ways to do this. A simple brute force approach is to create a new data set (or view), specify a length of 2 to a character variable and set that variable to the original "Panelby" variable. 

 

See if you can use this as a template

 

proc sgpanel data =s ashelp.iris;
  panelby species / rows = 3 layout = rowlattice;
  vbar PetalWidth;
run;

data plot;
   set sashelp.iris;
   length S $ 2;
   S = Species;
run;

proc sgpanel data = plot;
  panelby S / rows = 3 layout = rowlattice;
  vbar PetalWidth;
run;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

There are many ways to do this. A simple brute force approach is to create a new data set (or view), specify a length of 2 to a character variable and set that variable to the original "Panelby" variable. 

 

See if you can use this as a template

 

proc sgpanel data =s ashelp.iris;
  panelby species / rows = 3 layout = rowlattice;
  vbar PetalWidth;
run;

data plot;
   set sashelp.iris;
   length S $ 2;
   S = Species;
run;

proc sgpanel data = plot;
  panelby S / rows = 3 layout = rowlattice;
  vbar PetalWidth;
run;
PeterClemmensen
Tourmaline | Level 20

Alternatively, simply specify the $2. format

 

proc sgpanel data = sashelp.iris;
  panelby species / rows = 3 layout = rowlattice;
  vbar PetalWidth;
  format species $2.;
run;

Result:

 

 

SGPanel5.png 

ballardw
Super User

Your entire class needs to learn to post CODE and LOG entries using a code box on the forum to post text. Copy from the Editor or the Log and paste into a code box opened on the forum with either the </> or "running man" icon.

 

It is very hard to edit and show where code needs to be modified when presented with a picture.

Try adding (since I can't copy and paste text from a picture) to display only the first two letters of the text of Statecd:

FORMAT STATECD $2. ;

to the SGPANEL code.

 

Note: be careful if more than one value has the same formatted value such as Alabama and Alaska. They will be treated the same by the graphing or other procedures. Otherwise you need to create an additional variable for your PanelBy variable that has the desired code.

If you have a ZIPcode in the data you could use the function ZIPSTATE to create a two-letter state code from the ZIP to avoid a bunch of If/then/else statements.

 

I'm starting to think I should be able to get credit for this class with the number of questions posted here.

neeloofar
Fluorite | Level 6

You should add another format. If you add Format StateCd $StateCd2.;    it should format your response correctly. 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 929 views
  • 3 likes
  • 4 in conversation