René Nyffenegger
René Nyffenegger

Reputation: 40499

How do I put numbers right aligned?

How do I put numbers right aligned in a SAS data step?

data _null_;

  num =    1; put num=6.0;
  num =   10; put num=6.0;
  num =  100; put num=6.0;

run;

This data step puts

num=1
num=10
num=100

What I have wanted (and expected) was that it would put

num=     1
num=    10
num=   100

When I use the Zw.d format, the numbers are "correctly" right aligned, yet with the dreaded 0 padding.

Upvotes: 1

Views: 434

Answers (1)

DomPazz
DomPazz

Reputation: 12465

Problem is that pesky = sign you have in the put statement. It throws off the logic for how the PUT statement aligns variables.

See this aligns the variables:

data _null_;
  num =    1; put  num 6.;
  num =   10; put  num 6.;
  num =  100; put  num 6.;
run; 

like this:

     1
    10
   100

So if you want the num= to be in the log, you have to print that separately

data _null_;
  num =    1; put "num=" num 6.;
  num =   10; put "num=" num 6.;
  num =  100; put "num=" num 6.;
run;

Produces this:

num=     1
num=    10
num=   100

Upvotes: 1

Related Questions