Desktop productivity for business analysts and programmers

Format 1,000,000 to display1.0

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 94
Accepted Solution

Format 1,000,000 to display1.0

Hello,

In SAS Enterprise Guide, how can I change a column to display to the "thousandth"?  For example, if a number is $2,534,000 - I would like the result to show $2.534. 

I know I can divide a column by 100,000 but there are 60 columns and I don't want to do that for all 60 columns.

Thanks!


Accepted Solutions
Solution
‎08-04-2014 03:14 PM
Respected Advisor
Posts: 3,775

Re: Format 1,000,000 to display1.0

I think you need to consider these two Cautions from the documentation.

CAUTION:

The picture must be wide enough for the prefix and the numbers.

In this example, if the value –45.00 were formatted with NOZEROS., then the result would be 45.00 because it falls into the first range, low – –1, and the picture for that range is not wide enough to accommodate the prefixed minus sign and the number.

CAUTION:

The picture must be wide enough for an additional digit if rounding a number adds a digit to the number.

For example, the picture for the number .996 could be ‘99’ (prefix ‘.’ mult=100). After rounding the number and multiplying it by 100, the resulting number is 100. When the picture is applied, the result is .00, an inaccurate number. In order to ensure accuracy of numbers when you round numbers, make the picture wide enough to accommodate larger numbers.

I don't think you need but one range for positive numbers.

proc format;
  
picture million(round) 0-1e9=' 000009.9' (prefix='$' mult=0.00001);
   run;
data null ;
   a = 49999;
   b =
70000;
   c =
100000;
   d =
1e6;
  
x = 19875000 ;
   y = 200000000;
  
format _all_ million. ;
   put (_all_)(=best.);
   put (_all_)(=million.);
   run;


a=49999 b=70000 c=100000 d=1000000 x=19875000 y=200000000

a=$0.0 b=$0.1 c=$0.1 d=$1.0 x=$19.9 y=$200.0

View solution in original post


All Replies
Esteemed Advisor
Esteemed Advisor
Posts: 7,221

Re: Format 1,000,000 to display1.0

Well you could try using arrays:

data want;

     set have;

/* Way 1 where columns not the same = array myarray{60} var1 var2 var3 etc. - long winded */

     array var{60};   /* This assumes the variables are named var1 var2 etc. */

     do I=1 to 60;

          var{I}=var{I}/100000;

     end;

run;

Alternatively you could generate the either by macro or call execute.

Respected Advisor
Posts: 3,775

Re: Format 1,000,000 to display1.0

This can be done with a PICTURE FORMAT and the appropriate multiplier applied to the range.  See the documentation I believe there is an example that is just what you are looking for or very close.

Valued Guide
Posts: 3,206

Re: Format 1,000,000 to display1.0

You probably have a numeric dollar format that has a format applied to that showing the $ ...... SAS(R) 9.4 Formats and Informats: Reference

With proc format you can define your own one with a multiply-factor.   Just change the formats not the data.  Base SAS(R) 9.4 Procedures Guide, Second Edition

---->-- ja karman --<-----
SAS Super FREQ
Posts: 8,720

Re: Format 1,000,000 to display1.0

Hi:

  Data_Null and Jaap are recommending the right way to deal with this issue -- changing the data is unnecessary. PROC FORMAT will do this for you and the documentation has an example of creating the "BIGMONEY." format for an example such as yours: Base SAS(R) 9.4 Procedures Guide, Second Edition (The example is entitled "Example 3: Creating a Picture Format for Large Dollar Amounts").

cynthia

Frequent Contributor
Posts: 94

Re: Format 1,000,000 to display1.0

Thanks everyone for the responses.  Cynthia - thanks for the link to the Big Money example.  That helped, but I stil lhave an issue.  Here is my code.  The format works for  x and y.  However, a, b and c do not.  I should get:

a = $0.0

b = $.01

c= $.01

Instead I get:

a= $99.0

b= $1

c=$1

Your assistance is greatly appreciated!

********************

proc format;

   picture million (round fuzz=0)

    0 -< 50000 = '00.0' (prefix='$' mult=0.0)

  50000 -< 1000000 = '00.0' (prefix='$' mult=0.00001)

  1000000 -< 1000000000='0000.0' (prefix='$' mult=.00001);

   run;

  data null ;

   a = 49999;

   b = 70000;

   c = 100000;

   x = 19875000 ;

   y = 200000000;

   format a million. ;

   format b million. ;

   format c million. ;

   format x million. ;

   format y million. ;

run ;

Solution
‎08-04-2014 03:14 PM
Respected Advisor
Posts: 3,775

Re: Format 1,000,000 to display1.0

I think you need to consider these two Cautions from the documentation.

CAUTION:

The picture must be wide enough for the prefix and the numbers.

In this example, if the value –45.00 were formatted with NOZEROS., then the result would be 45.00 because it falls into the first range, low – –1, and the picture for that range is not wide enough to accommodate the prefixed minus sign and the number.

CAUTION:

The picture must be wide enough for an additional digit if rounding a number adds a digit to the number.

For example, the picture for the number .996 could be ‘99’ (prefix ‘.’ mult=100). After rounding the number and multiplying it by 100, the resulting number is 100. When the picture is applied, the result is .00, an inaccurate number. In order to ensure accuracy of numbers when you round numbers, make the picture wide enough to accommodate larger numbers.

I don't think you need but one range for positive numbers.

proc format;
  
picture million(round) 0-1e9=' 000009.9' (prefix='$' mult=0.00001);
   run;
data null ;
   a = 49999;
   b =
70000;
   c =
100000;
   d =
1e6;
  
x = 19875000 ;
   y = 200000000;
  
format _all_ million. ;
   put (_all_)(=best.);
   put (_all_)(=million.);
   run;


a=49999 b=70000 c=100000 d=1000000 x=19875000 y=200000000

a=$0.0 b=$0.1 c=$0.1 d=$1.0 x=$19.9 y=$200.0

Community Manager
Posts: 2,696

Re: Format 1,000,000 to display1.0

This thread and the BIGMONEY example prompted me to complete this blog post, which I had been mulling for a while:

Format your data like a social media superstar - The SAS Dummy

SAS formats are super powerful, and PICTURE formats can be immensely useful.  Enjoy!

Chris

☑ This topic is SOLVED.

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

Discussion stats
  • 7 replies
  • 2923 views
  • 3 likes
  • 6 in conversation