BookmarkSubscribeRSS Feed
Emma8
Quartz | Level 8
Hi. I have the following format.
Proc format;
Value
1=“kids reference”
2=“teenagers 4(3-6)”
3=“older 16(10-18)”
;

How can I align by “-“ when print out. Thank you.
15 REPLIES 15
Reeza
Super User

I don't think the forum is showing what you want. When typing out data that has a fixed structure try using a code block - 8th icon above the box you're typing in after hitting Reply (not Quick Reply).

ballardw
Super User

Considering that the posted Proc Format code will not run because it using "pretty" quotes instead of programming quotes...

 

You might get close using code similar to:

Proc format;
Value
1="kids reference"
2="teenagers 4 (3-6)"
3="older    16(10-18)"
;

But anything displaying these values with a proportional font (any thing not monospace like Courier or SAS Monospace) will likely have some difference of appearance as different letters take up different amounts of space and multiple spaces are almost always going to be significantly reduced.

 

You really need to show how/where you expect to use that format as well.

As a quick reference to differences in propottional fonts.

iiiiiiiiiiiiiii

wwwwwwwwwwwwwww

Those two lines above both contain 15 characters. I will bet a short stack of $$ that the row of i values is lots shorter than the w values.

 

 

Emma8
Quartz | Level 8
I did as you did but when I proc sgplot that variable it’s would not line up nicely as formatted by the “-“
Reeza
Super User
Can you provide a fully worked example then so we can test the code and solutions?
Emma8
Quartz | Level 8
Proc sgplot data...
Format Cc Ccformat.;
Run;
ballardw
Super User

1) we need data

2) we need the entire code to recreate your graph which means:

3) we need to know the ODS destination and the ods style in affect when you generate the graph,

and possibly 4) ods graphics options set.

 

And then describe where this is appearing that it should "align". In a legend? Axis? Axistable?

Emma8
Quartz | Level 8
Thank you.


data test;
set sashelp.class;
if age in (12,13) then gr=1;
else if age =14 then gr=2;
else gr=3;
run;

proc sort data=test;
by gr;
run;
proc format;
value gr
1="kids Reference"
2="teenagers 9 (4-24)"
3="old 78 (32-189)"
;
proc template;
define style mystyle;
parent=styles.sasweb;
class graphwalls /
frameborder=on;
class graphbackground /
color=white;
end;
run;
ods graphics on / reset=all;
ods html style=mystyle path='.' file='newgraph.html';
ods graphics / reset=all width=6.5in height=4.5in border=off ;
legend1 label=none;
proc sgplot data=test DATTRMAP=attrmap1;
scatter x=weight y=Height /group=gr ;
keylegend / location=outside position=bottom NOBORDER down=4;
label gr='Age, years OR (95% CI)';
format gr gr.;
run;
Reeza
Super User

This worked for me:

 

proc format;
value gr
1="kids Reference"
2="teenagers 9 (4-24)"
3="old          78(32-189)"
;

That being said, HTML alignment is a tricky thing. If you have a different resolution shown on screen or a different zoom level I'm not sure you can fix that component. You may want to consider using a annotate option to add that information into your graph instead if positioning is super important.

Emma8
Quartz | Level 8
Thanks.
But does not line up by “-“—does not produce what I wanted
Reeza
Super User
That's exactly the point of my latter comment. It did for me, but won't for you and there's almost no way to guarantee that AFAIK unless you explicitly use annotate and control the location on the graphic. The way HTML renders by default makes this difficult. I'm not even sure annotate would get around this...you probably want to be generating SVG type graphics maybe instead? Or fixed images that can't scale?
Emma8
Quartz | Level 8
Don’t know. It generates html graph. How can I annotate?
ballardw
Super User

@Emma8 wrote:
Thanks.
But does not line up by “-“—does not produce what I wanted

Did you read the bit I posted about the i's and w's? That is what is going on here. Spaces take up less area than most characters with a proportional font.

 

You can try adding more spaces in the format and things may get close but exact alignment is very likely a hit and miss(mostly) proposition. However as soon as you get this to sort of work with one set of options then the next time you do this and have a different measure and interval to display the trial and error begins again.

 

You might consider moving to GTL and have second graph that shows a forest plot of the OR and CI values (for the groups with such) under the scatterplot. Which may provide a better feel for the data than the few digits displayed.

Emma8
Quartz | Level 8
Thanks.
I just want to line up by this symbol “-“
ballardw
Super User

Please post code into a code box opened with either the </> or "running man" icon as in my example. The message windows will reformat code removing blanks. So any attempt at alignment in your proc format code has been removed.

 

And since you referenced yet another data set, the DATTRMAP set, to duplicate your exact results we would need that as well.

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against.

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 15 replies
  • 1453 views
  • 5 likes
  • 4 in conversation