There are different kinds of formats. The ones that you define with an INVALUE statement are more accurately called INFORMATS and those are meant to be used to read data INTO SAS.
The formats that you define with a VALUE statement are called FORMATS and those are meant to be used to display data from SAS into a certain format. For example:
value $team 'UNC' = 'Tar Heels'
'DUKE' = 'Blue Devils'
'NCSU' = 'Wolfpack'
'NMSU' = 'Aggies'
'UTEP' = 'Miners';
so first you define the format, then you USE the format in a format statement:
format school $team.;
Then, there's a type of format called a PICTURE format. You can read about it in the PROC FORMAT documentation under the description for the PICTURE statement. You still USE the created format in a FORMAT statement -- what's different is how you DEFINE the format -- with a PICTURE statement. Some folks like to think of the VALUE type format as being used for "recoding" or setting categories; while they think of the PICTURE type format as "masking" or making a "pattern" for the display format. For example, this comes straight from the documentation on a PICTURE statement:
picture pay low-high='000,009.99' (prefix='$');
and the format statement would be:
format salary pay.;
In the above PICTURE or mask for the salary variable, 2 decimal places will always be shown and there will always be -something- in the 1's place -- for example, the numeric value .23 would be displayed as $0.23 with the above format. The documentation is very good on when and how you use the 0 digit selectors vs the non-zero digit selectors and about the prefix possibilities.
And again and again, THANK YOU, Cynthia! The first link you provided was quite similar to what I was looking for, although I'd still like to be able to put parentheses around my negative monetary amounts. Is there anything similar to PREFIX for placing something at the end of a value?
INPUT X ;
ACCTDOL = X;
FORMAT x best14.4 ACCTDOL ACCTDOL. DOL DOL. ;
PROC PRINT data=testfmt;
TITLE 'Using Picture Formats';
VAR X ACCTDOL DOL ;
Note how the close paren goes into the Picture and you just use a different prefix for the negative dollar range [low-<0 means less than 0 or negative values], where [0-HIGH] means all the positive values.
This is the output from the above program:
Using Picture Formats
The documentation has a good explanation about how the Picture is filled from RIGHT to LEFT. So 1) your picture has to be big enough for the entire "mask" including characters like leading $ and 2) if you're not careful to make it big enough you get truncation and 3) by default, you don't get rounding. The doc talks about that.
Thanks Cynthia for your always welcome assistance. Here's another question.... I notice that the dollar sign "floats" in the field according to the size of the monetary value.... how do I create a format that keeps the dollar sign in a "fixed" olace in the field?
It sticks in my mind that this is how PICTURE works and you can't change it. The FILL option fills AFTER the picture has been applied (so, for example, you could create a mask of
But you have gotten the last neuron of my PICTURE knowledge. If I really, really, had to get a $ in the leftmost position, for LISTING only, I'd create a character variable from the amount and substring or concatenate the $ into the new character variable. Another possibility is to NOT show ANY dollar signs in the report rows and just show a $ on the LAST total row or at the bottom of the report -- which you can do with PROC REPORT and a CALL DEFINE for format on the RBREAK row. Maybe somebody else has a better idea or you could try Tech Support.
Using FILL and Creating a Character Variable
Personally, I don't like how the OTHER column looks in the output. And, in a proportional spaced font, such as that used with
HTML, RTF, etc, I doubt that it would all line up, anyway. Which means that as a stored process, even if you LIKE the way it looks in the ASCII output version,
it will NOT look that same way in EG or the SAS Add-in or Web Report Studio.
That makes sense to me.... I removed the dollar sign, and it looks A LOT better. Since this report I'm doing is for our finance/accounting people, I certainly hope they realize that certain columns of info are monetary.....