BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
new_sas_user_4
Obsidian | Level 7

I am using dollar12. format in my proc report and for the negative values I get the negative sign "-" after the dollar sign ($-10)

 

Ideally, I would want the negative sign to be before the dollar sign (-$10)

Is there a way to do this?

 

data _null_;
A=-10.1;
putlog A= dollar12. ;
run;

 

Thanks !!

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

1. Change so that the default length will show the $

2. Change so that the other format is default dollar format for values above 0. 

 

proc format; 
picture mycurrencyfmt (default =22 )
low - 0 = '000,000,099.99' (prefix = '-$')
other = [dollar22.] ;

run;

data demo;
input value;
format value mycurrencyfmt.;
cards;
25
45
3993
34343434314
-3434343
-234
-2334
-34343413413413.23
;;;;
run;

proc print;run;

@new_sas_user_4 wrote:

Yes, this is what I ran:

proc format;
picture myCurrencyFmt
low - 0 = '999,999,999.99' (prefix = '-$')
0 - high = '999,999,999.99' (prefix = '$');
run;

data _null_;
A=-10.1;
putlog A=myCurrencyFmt.;
run;

 

I got A=000,000,010.10 in the log!


 

View solution in original post

8 REPLIES 8
Reeza
Super User

I think you need a custom format.

Untested but something like this I assume, untested.

 

proc format;
picture myCurrencyFmt
   low - 0 = '999,999,999.99' (prefix = '-$')
   0 - high = '999,999,999.99' (prefix = '$');
run;

@new_sas_user_4 wrote:

I am using dollar12. format in my proc report and for the negative values I get the negative sign "-" after the dollar sign ($-10)

 

Ideally, I would want the negative sign to be before the dollar sign (-$10)

Is there a way to do this?

 

data _null_;
A=-10.1;
putlog A= dollar12. ;
run;

 

Thanks !!


 

new_sas_user_4
Obsidian | Level 7

Using the below I get : NOTE: Variable myCurrencyFmt is uninitialized.
A=-10.1 

 

proc format;
picture myCurrencyFmt
low - 0 = '999,999,999.99' (prefix = '-$')
0 - high = '999,999,999.99' (prefix = '$');
run;

data _null_;
A=-10.1;
putlog A=myCurrencyFmt ;
run;

Reeza
Super User
You forgot the period after the format name in your code so it's trying to find a variable with that name.
new_sas_user_4
Obsidian | Level 7

thanks Reeza.

 

I see A=000,000,010.10 in the log now!

 

Is there a way to do this using SAS formats ?

Reeza
Super User

That is a format - note PROC FORMAT. Did you remember the prefix portion, why isn't that showing?


@new_sas_user_4 wrote:

thanks Reeza.

 

I see A=000,000,010.10 in the log now!

 

Is there a way to do this using SAS formats ?


 

new_sas_user_4
Obsidian | Level 7

Yes, this is what I ran:

proc format;
picture myCurrencyFmt
low - 0 = '999,999,999.99' (prefix = '-$')
0 - high = '999,999,999.99' (prefix = '$');
run;

data _null_;
A=-10.1;
putlog A=myCurrencyFmt.;
run;

 

I got A=000,000,010.10 in the log!

Reeza
Super User

1. Change so that the default length will show the $

2. Change so that the other format is default dollar format for values above 0. 

 

proc format; 
picture mycurrencyfmt (default =22 )
low - 0 = '000,000,099.99' (prefix = '-$')
other = [dollar22.] ;

run;

data demo;
input value;
format value mycurrencyfmt.;
cards;
25
45
3993
34343434314
-3434343
-234
-2334
-34343413413413.23
;;;;
run;

proc print;run;

@new_sas_user_4 wrote:

Yes, this is what I ran:

proc format;
picture myCurrencyFmt
low - 0 = '999,999,999.99' (prefix = '-$')
0 - high = '999,999,999.99' (prefix = '$');
run;

data _null_;
A=-10.1;
putlog A=myCurrencyFmt.;
run;

 

I got A=000,000,010.10 in the log!


 

new_sas_user_4
Obsidian | Level 7

Awesome!!

Thanks!! 🙂

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 8 replies
  • 2821 views
  • 0 likes
  • 2 in conversation