Format large number?

Reply
Occasional Contributor
Posts: 17

Format large number?

I am running some Proc SQL queries e.g. MAX(variable) where the result cannot be displayed correctly due to the size of the number. How do I format this within the query to see the actual number?

Valued Guide
Posts: 534

Re: Format large number?

Can you add an example of your currently attemped code and data so we get the picture (literally)?

 

Thanks in advance, Jan.

Respected Advisor
Posts: 4,736

Re: Format large number?

@amorts

The correct answer might depend on the details of what you're doing which you haven't told us. As a generic answer: Try using format BEST32., i.e. in your SQL:

 

select

  max(<variable>) as max_var format=best32. ,

  ....

Occasional Contributor
Posts: 17

Re: Format large number?

Ok thanks. I don't have access to the code right now but I'll post an example on Monday
Occasional Contributor
Posts: 17

Re: Format large number?

Ok so the field is stored as a num format 17.2.

The result from the max is 5E8

Applying the best32. Works and returns the result 500000000
Super User
Super User
Posts: 8,116

Re: Format large number?

You can specify the format to attach to a variable you are deriving in SQL code by adding the FORMAT= keyword.

data have ;
  num=5E13 ;
  format num 17.2 ;
run;
proc sql ;
  create table want as
    select max(num) as unformatted 
         , max(num) as formatted format=17.2 
    from have
  ;
quit;

proc print data=want;
run;
Obs    unformatted            formatted

 1          5E13      50000000000000.00
Occasional Contributor
Posts: 17

Re: Format large number?

Ok thanks.
Why doesn't it inherit the data type from the incoming data? What does it default to?
Super User
Super User
Posts: 8,116

Re: Format large number?

PROC SQL will not assign formats to derived variables. It really cannot tell the difference between a function like MAX() that does not change the type or range of values and an operation like DATEPART() that could change the meaning of the numbers or SUM() that could change the range of values and hence require a different width for format.

 

SAS will normally using BEST12. format to display numbers that do not have a format specification.

Ask a Question
Discussion stats
  • 7 replies
  • 684 views
  • 0 likes
  • 4 in conversation