An Idea Exchange for SAS software and services

by Frequent Contributor
on ‎10-25-2013 05:00 PM

The left() is not necessary if you use alignment modifier of the put function.

E.G. put(num_var, 8. -L)   is equivalent to   left(put(num_var, 8.)).

(You can also specify right and centre alignments with -R and -C.)

by Super User
on ‎10-25-2013 06:31 PM


by Frequent Contributor
on ‎10-26-2013 07:13 AM


(Default length of returned value of CATS() is 200)

by Super User
on ‎11-01-2013 07:35 PM

So for your example this code is not really any more difficult that what you want and more clearly shows the intent of the formatting rules.

age2 = catx(' '
           ,catx(' ± ',put(mean, 5.1),put(std, 4.1))
           ,cat('(',catx(' - ',put(min, 3.), put(max, 3.)),')')

by Contributor jaredp
on ‎11-04-2013 11:07 AM

Tom, you're too good at writing code!  I agree with you that it shows intent, which is nice.  But the code is not very clear, which makes it more difficult to use.

But code should never replace documentation.  As such, I'd prefer Jerry's first suggestion and then specify any intent with a /*comment*/

I don't know any of the limitations of proc fcmp, but perhaps one could create the tlp() function with that?

by Frequent Contributor
on ‎11-04-2013 10:52 PM

data _null_;
  char_val = put(num_var, 8.);
  char_val_length = length(char_val);
  put char_val= / char_val_length=;


The PUT function gives the compiler enough info to allocate 8 bytes to char_val, instead of a default of 200.  So unless num_var is 8 digits long, there will always be spaces padding the result, however its aligned.

Substitute a TLP function (whether or not created with Proc FCMP) for the PUT, and the same applies.

So catering for all the wanted and unwanted spaces still falls to the concatentation operation.  And how you do that is just personal preference.  Tom's solution is nice or you might prefer:

age = cat(strip(put(mean, 5.1)), " ± ", strip(put(std, 4.1))), " (", strip(put(min, 3.)), " - ", strip(put(max, 3.)), ")");

... or any number of variations.

I think the bottom line is that a TLP function couldn't do what is hoped for.

by SAS Employee HenrikDorf
on ‎12-20-2013 07:46 PM

While you wait . this might do Smiley Happy

Use # as placeholders and translate them to spaces after cats has finished.

age3=translate(cats(put(mean, 5.1),"#±#",put(std, 4.1),"#(",put(min, 3.),"#-#",put(max, 3.),")")," ","#");
Idea Statuses
Top Liked Authors