BookmarkSubscribeRSS Feed
deleted_user
Not applicable
In working woith a monetary field, is there a way of keeping a dollar sign in the first position, regardless of the size of an actual money amount? Something like:

$ 23.12
$ 4567.12
$ 54321.12

I tried using a picture clause and didn't get far.... I've also searched the Customer Support Center samples and didn't see anything.

If anyone can help, I sure would be most appreciative. Thanks in advance!
3 REPLIES 3
Cynthia_sas
SAS Super FREQ
Hi:
Remember that by default, numeric variables are right justified. That will never put the dollar sign in a fixed position (unless, of course, all your numbers are the same number of digits). The only way to get the dollar sign into a "fixed" position is to turn your number into a character string and then put the $ in front of the character string (see CHARDOL variable and compare how it looks in LISTING vs ODS HTML).

If you left justify the number, using a PICTURE format, you may find the dollar signs lining up.

The program below makes some data and by comparing the ODS HTML and the LISTING output, you will see the difference between the outputs and perhaps, depending on what you want to create, you will find an answer to your question.

My tendency would be to leave the $ off the rows and only put a $ on the last summary row, instead of trying to force a lined up $ (using call define). The character variable solution looks attractive, but then you can't summarize on a character variable -- so that's a down side. And depending on your client application in which this format is being used the picture format or character variable may not align the way you want anyway.

cynthia
[pre]
PROC FORMAT;
PICTURE DOL LOW-HIGH = '000,000,009.99' (PREFIX='$ ');
PICTURE flDOL LOW-HIGH = '000,000,009.99' (PREFIX='$ ' fill='*');
RUN;

DATA testfmt;
INFILE DATALINES;
INPUT DOL ;
flDOL = dol;
x = dol;
chardol = '$'||right(put(dol,comma14.2));
FORMAT x best14.4 DOL DOL. flDOL flDOL.;
return;
DATALINES;
12345
0
187.65
.23
14.2
987.234
1.234
101.23
;
RUN;

options nodate nonumber linesize=70;

ods listing;
ods html file='c:\temp\leftjust.html' style=egdefault;

PROC report data=testfmt nowd;
TITLE 'Using Picture Formats with default justify (right)';
column X DOL flDOL chardol;
define x /display;
define dol /display;
define fldol /display;
define chardol / display;
RUN;

PROC report data=testfmt nowd;
TITLE 'Using Picture Formats with left justify and ODS';
column X DOL flDOL chardol;
define x /display style(column)={just=left};
define dol /display style(column)={just=left};
define fldol /display style(column)={just=left};
define chardol /display style(column)={asis=on};
RUN;
ods html close; [/pre]
deleted_user
Not applicable
Thanks, Cynthia.....

So there's nothing that can remain a numeric dollar format, yet display with a nicely arranged dollar sign on the left. Well, darn it! I understand what you're saying about things lining up..... too bad there's not something there in SAS that'll transcend from one format to another and still look cosmetically nice!

I appreciate your information and thanks many times over!
Cynthia_sas
SAS Super FREQ
Well, I understand your disappointment, but to me, having a dollar sign all lined up on every report line would be visually distracting. I like the look of this output with the dollar sign on the summary report line instead of on every report line.

[pre]
proc report data=sashelp.shoes nowd;
where region = 'Africa';
column region product sales;
define region /group;
define product /group;
define sales /sum f=comma14.2;
rbreak after /summarize;
compute sales;
if _break_ = '_RBREAK_' then do;
call define(_col_,'format','dollar14.2');
end;
endcomp;
run;
[/pre]

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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