Hello All,
I am trying to create a Indian currency type using PROC FORMAT , I found some sas documentation on creating currency format but there is no clear explanation about the syntax and values they used. Below is the sample code I found in sas documentation, Could any one explain how it works?? And any suggestion on how to insert a image instead of some values using proc format???
proc format; picture aud low-<0='0,000,000,009.00' (prefix='-AU$' mult=100) 0–high='0,000,00,009.00 ' (prefix='AU$' mult=100); picture sfr low-<0='0,000,000,009.00' (prefix='-SFr.' mult=100) 0–high='0,000,00,009.00 ' (prefix='-SFr.' mult=100); picture bpd low-<0='0,000,000,009.00' (prefix='-BPd.' mult=100) 0–high='0,000,00,009.00 ' (prefix='BPd.' mult=100); run; data currency; input aud sfr bpd 12.2; datalines; 12345 12345 12345 0 0 0 -12345 -12345 -12345 ; proc print data=currency noobs; var aud sfr bpd; format aud aud. sfr sfr. bpd bpd.; title 'Unique Currency Formats'; run;
A picture format is just a template into which raw data is inserted; the result will be dynamic.
A value format has fixed values for one raw value or a range of raw values; with a value format you would need to have a separate entry for every number conceivable.
A zero in the format string means "insert a digit here, but omit if it's a leading zero". A nine means "insert the digit in any cases". After the first 9, all 0's will always display a digit.
All other characters except 0 and 9 will appear as-is in the resulting string, which means that the period or commas have no special meaning. Therefore the number has to be multiplied with 100 to display correctly.
The prefix will display in front.
And a strong hint:
NEVER put your code through any kind of word processor if you intend to further use it in a program. Your example code has UTF-hyphens in it (in the "0-high" phrases) that make it unusable without correcting.
You can't use images in the prefix, but you can use UTF characters (within strings they are OK) if your SAS is running with UTF encoding.
This works:
proc format;
picture aud
low-<0='0,000,000,009.00' (prefix='-AU$' mult=100)
0-high='0,000,000,009.00' (prefix='AU$' mult=100)
;
picture sfr
low-<0='0,000,000,009.00' (prefix='-SFr.' mult=100)
0-high='0,000,00,009.00 ' (prefix='-SFr.' mult=100)
;
picture bpd
low-<0='0,000,000,009.00' (prefix='-BPd.' mult=100)
0-high='0,000,00,009.00 ' (prefix='BPd.' mult=100)
;
run;
data currency;
input aud sfr bpd 12.2;
datalines;
12345 12345 12345
0 0 0
-12345 -12345 -12345
;
run;
proc print data=currency noobs;
var aud sfr bpd;
format aud aud. sfr sfr. bpd bpd.;
title 'Unique Currency Formats';
run;
A picture format is just a template into which raw data is inserted; the result will be dynamic.
A value format has fixed values for one raw value or a range of raw values; with a value format you would need to have a separate entry for every number conceivable.
And one more clarification, created format is getting stored as numeric for the assigned variable .is there any possibility ti keep the format in 'currency data type' itself?
SAS itself knows only two data types: numeric and character.
Some SAS interfaces (like SAS Studio or Enterprise Guide) interpret certain formats to indicate special "types" like date, time or currency, but this works only for those formats the interfaces know about. Custom formats defined by users will have no effect in this regard.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.