SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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
Quartz | Level 8

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
Quartz | Level 8

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
Quartz | Level 8

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
Quartz | Level 8

Awesome!!

Thanks!! 🙂

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 8 replies
  • 3609 views
  • 0 likes
  • 2 in conversation