BookmarkSubscribeRSS Feed
Waliyya
Calcite | Level 5

Hello everyone,

Happy new year to you all. I have a question concernant a command I've come across and that I need to do my project. Here it is :

data projet.portefeuille_1;

set projet.portefeuille;

format rdt_portf 9.5;

rdt_portf=1/3*rdt_al+1/3*rdt_bnp+1/3*rdt_brt;

run;

It is the "9.5" I'm not getting. What does it mean ?? Because when I change it to 10.5 or to 8.6 for example, it changes my data values completely.

Can you help me please?

Thank you in advance.

2 REPLIES 2
Tom
Super User Tom
Super User

It should not change the values, just how SAS displays them.

9.5 means that it will use 5 decimal spaces and a total of 9 characters to display the value.

Cynthia_sas
SAS Super FREQ

Hi,

  I suggest you review some of the concept information about SAS data, especially the information about FORMATS. There is a good documentation topic entitled "Essential Concepts of Base SAS Software" that discusses variable attributes, such as formats.

  Basically, the format (what you specify in the FORMAT statement) controls how the variable value is printed or displayed in procedures like PROC PRINT (for example). The FORMAT statement does NOT impact the internally stored value, but, instead just impacts the DISPLAY of a variable value.
      

  Usually a format such as you show: format rdt_portf 9.5; would provide instructions to SAS to take the value for the RDT_PORTF variable and use 9 total print positions to display the value. Of the 9 total print positions, 5 positions would be used for the decimal portion of the number and 1 position would be used for the decimal (punctuation).  So, effectively, that would be:

123456789  <--- number of print positions

###.#####  <--- what you are asking for

568.94302  <---example
    

But a format of 8.6 implies that you want SAS to use 8 total positions and use 6 of the positions for decimal places and 1 position for the decimal

12345678  <--- number of print positions

#.######  <--- what you are asking for

3.141592  <--- example

So a format of 11.6 would be asking for this:

####.######

5489.356124 <--- example

And a format of 12.6 would be asking for this:

#####.######

43983.849211 <--- example

      

As you might imagine the consequences of specifying a format that is too small might cause unwanted rounding or cause the number not to display correctly. So for example, if you know that your biggest salary is 123456.78 and you want to display that number with a dollar sign, commas, a decimal point and 2 positions, then you need a minimum of 11 total print positions: $123,456.78 because you have 8 numbers, a decimal point, a comma and a dollar sign, each of which takes a print position. So the format you would specify in this case would be

format salary dollar11.2; And, it would be wrong to make the format something like dollar8.2, because that is not "enough" print positions to display the number the way you want.

  It is up to you to know how "big" your numbers are and what type of punctuation you want in the number (. , $ %) every character you use takes a print position. So you have to make your format number "wide" enough for the number, decimal places and other punctuation to fit. Here's a program you can run, which was used to produce the output shown in the attached explanation. Basically, every variable in the test data has the same internal value: 1234.56 but each variable is formatted differently. Note that if you make the format too small, you most often get undesirable results. Also note that the INTERNAL value of the variable is not impacted by the format assigned to the variable. Only the external display of the number is impacted by the format. The report specifies Courier New as the font for display purposes, so that each character takes up the same amount of display space. Otherwise, in a proportional font, the number 1 takes up less "display" space than the number 8.

Cynthia

data testfmt;

  a = 1234.56;

  b = 1234.56;

  c = 1234.56;

  d = 1234.56;

  e = 1234.56;

  f = 1234.56;

  g = 1234.56;

  h = 1234.56;

  i = 1234.56;

run;

  

proc print data=testfmt label split='*'

  style(header)={font_face='Courier New'};

  title 'Same internal number: 1234.56';

  var a b c d e f g h i/ style(column)={font_face='Courier New'};

  format a 11.1 b 11.2 c 11.3 d 11.4 e 8.2 f 8.1 g 8.0 h 3.2 i 2.1;

  label a= 'a*format is 11.1'

        b= 'b*format is 11.2'

        c= 'c*format is 11.3'

        d= 'd*format is 11.4'

        e= 'e*format is 8.2'

        f= 'f*format is 8.1'

        g= 'g*format is 8.0'

        h= 'h*format is 3.2'

        i= 'i*format is 2.1';

run;


explain_format_usage.png

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2802 views
  • 0 likes
  • 3 in conversation