DATA Step, Macro, Functions and more

How to put '0' in format '0.00' and '0.000'

Accepted Solution Solved
Reply
Regular Contributor
Posts: 214
Accepted Solution

How to put '0' in format '0.00' and '0.000'

[ Edited ]

Hi all,

 

I have some '0' values in my table. When I put it in character format :

 

 

put (x,best.)

 

 

and then list in the table using Proc Report:

 

 

define var2 / " Column_name " style(header)=[cellwidth=10.5%] style(column)=[just=d posttext='    '] ;

I receive the following issue:

 

The column where I have just zero values and values without decimal are shifted right ( I marked green the line that should be shifted left ). I think that put '0' in the view' '0.000' will be enough to align the figures to the center. Have you ever faced the issue and what could be a solution for the case?

 

2.jpg

 

Thank you!

 


Accepted Solutions
Solution
‎11-02-2017 12:02 PM
Regular Contributor
Posts: 214

Re: How to put '0' in format '0.00' and '0.000'

The solution was offered by one kind colleague:

 

define var2 / "Cohort XXXX" style(header)=[cellwidth=11.5%] style(column)=[just=c protectspecialchars=off pretext="\qj\tqdec\tx800 "] ;

Thus special 'report' code was used:

[just=c protectspecialchars=off pretext="\qj\tqdec\tx800 "] 

where 800 can vary to shift the text. It is important to keep space after 800. 

View solution in original post


All Replies
Super User
Posts: 5,915

Re: How to put '0' in format '0.00' and '0.000'

Posted in reply to DmytroYermak
Well put using a different format, like 4.2 or 5.3.
Even though I'm a bit allergic about storing continues numerical values as strings, buti assume that you have very specific display requirements.
Data never sleeps
Super User
Posts: 13,913

Re: How to put '0' in format '0.00' and '0.000'

Posted in reply to DmytroYermak

Are you attempting to align decimal points in character values? I don't think that is what the decimal align expects.

 

Also creating a character value with Put can create leading spaces which are significant when it comes to attempting to align anything.

 

Please look at this code:

data junk;
   x=0;
   y1= quote( put(x,best.) );
   y2= quote( put(x,best3.) );
   y3= quote( put(x,best5.) );
   y4= quote( put(x,best. -L) );
run;

The quotes in the various Y values are to outline the resulting blanks in the created variable. Any format length longer than the value needs, except the Z format for leading 0's, will create leading blanks unless the -L option (to left justify the result) on the Put function is used.

 

Solution
‎11-02-2017 12:02 PM
Regular Contributor
Posts: 214

Re: How to put '0' in format '0.00' and '0.000'

The solution was offered by one kind colleague:

 

define var2 / "Cohort XXXX" style(header)=[cellwidth=11.5%] style(column)=[just=c protectspecialchars=off pretext="\qj\tqdec\tx800 "] ;

Thus special 'report' code was used:

[just=c protectspecialchars=off pretext="\qj\tqdec\tx800 "] 

where 800 can vary to shift the text. It is important to keep space after 800. 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 292 views
  • 1 like
  • 3 in conversation