The SAS picture formats are a kind of template which is being used to display data in a particular format.
For example phone numbers written with space after each digits and country code, commas and dashes in the digits, etc.
Similarly you can picture format dates, big amounts with spaces and commas, currency sign, and you can even add background colours as well.
In this article you’ll learn:
→ SAS Picture Format to display Date
→ SAS Picture Format for big Amount
→ SAS Picture Format with Background Colours
→ SAS Picture Format to display Mobile Number
→ SAS Picture Format to display Salary with Currency
In fact you can append some text after formatted numbers. For example “mobile number” followed by text “- Mobile”.
- “9876543210 – Mobile”
- “1234567890 – Mobile”
Syntax is very similar to proc format invalue. The only change here is PICTURE keyword in place of INVALUE.
Syntax:
proc format library=libref;
picture format_name
low-high='<_format here_>' (<options>);
run;
In the below example demonstrated how a 10 digits mobile number can be formatted with a group of two digits and space in between.
For example:
Mobile number 9876543210 formatted as: 98 76 54 32 10
proc format;
picture fmtMobile
00000-9999999999='99 99 99 99 99'
other='99 99 99 99 99';
run;
data _null_;
mobile_nr=9876543210;
put mobile_nr=;
/* print value using user defined format fmtMobile. */
put mobile_nr=fmtMobile.;
run;
Now create a new dataset “work.staff” using the following data step procedure to demonstrate a few more examples.
You’ll use this data set to create and apply picture formats on various variables to display data in some standard formats.
/* create a new dataset */
data staff;
input Name & $16. IdNumber $ Salary
Site $ HireDate date9. Mobile;
format hiredate date9.;
datalines;
Nartinez, Jaria 8981 49014 US2 10FEB2013 1996543210
Kinth, Robert 8460 32181 BR1 23MAY2007 2848883517
Carrell, Joseph 6824 49503 US1 17JUN2012 4852543216
David, Brad 3777 28574 BR2 28JUL2006 3983982985
Leung, Brenda 4803 44372 BR1 19OCT2012 4476273623
Pal, Jimmy 4062 27957 BR2 10JAN2004 5099936043
Chenn, Lene 5089 31901 BR2 26JUN2005 6375449833
Orfali, Philip 0340 29008 US2 18FEB2007 7633734984
Patel, Mary 4358 46795 BR3 12SEP2011 8347479943
;
run;
1. Picture Format in SAS to Display Salary
The salaries are often displayed using commas and spaces with the respective currency sign.
In our raw data set salaries are stored in the simple numeric format. Let’s change that to display salary amount: 49014 as $49,014
/* SAS Picture format to display Salary */
proc format library=work;
picture uscurrency
low-high='000,000' (mult=1 prefix='$');
run;
proc print data=work.staff noobs label;
label salary='Salary in U.S. Dollars';
format salary uscurrency.;
title 'WORK.STAFF with a Format for the Variable Salary';
run;
In case if you want to adjust the salary and display salaries increased by 1.5 times then you can do that using option mult=1.5.
/* picture format to display increased Salary */
proc format library=work;
picture uscurrency
low-high='000,000' (mult=1.5 prefix='$');
run;
proc print data=work.staff noobs label;
label salary='Salary in U.S. Dollars (increased by 1.5x)';
format salary uscurrency.;
title 'WORK.STAFF with a Format for the Variable Salary';
run;
2. Picture Format in SAS to Print Amount on Check
If you observe the amount printed on check or demand drafts are in some different way. They add “*” before the actual amount. Let’s print that in SAS using proc format picture and fill=”*”option.
For example, salary amount 78912 should appear as “********$78,912”
/* sas picture format for Salary to print it on check */
proc format library=work;
picture uscurrency
low-high='000,000,000,000' (mult=1.5 fill='*' prefix='$');
run;
proc print data=work.staff noobs label;
label salary='Salary in U.S. Dollars';
format salary uscurrency.;
title 'WORK.STAFF with a Format for the Variable Salary for check';
run;
3. Picture Format for SAS Date
In the raw data set “staff” you have a HireDate column which has date in date9. format. You can create and apply picture format to display dates in some different formats.
For example, you can display date9. date 01JAN2025 as 2025-01-01 in yyyy-mm-dd format.
/* sas picture format for sas DATE */
proc format library=work;
picture dbdate
other='%Y-%0m-%0d' (datatype=date);
run;
proc print data=work.staff noobs label;
label salary='Salary in U.S. Dollars';
format salary uscurrency. HireDate dbdate.;
title 'WORK.STAFF with Formats for the Variables Salary & HireDate';
run;
4. Picture Format for Mobile number
You have a 10 digits mobile number in the staff data set. Now you want to display it as the first 3 digits dash next 3 digits space last 4 digits.
For example, mobile number 8347479943 will be displayed in this format: 834-747 9943
/* sas picture format for mobile number */
proc format library=work;
picture fmtMobile
other='999-999 9999';
run;
proc print data=work.staff noobs label;
label salary='Salary in U.S. Dollars';
format salary uscurrency. HireDate dbdate. Mobile fmtMobile.;
title 'WORK.STAFF with Formats for the Variables Salary, HireDate & Mobile';
run;
5. Proc format with background colour and Picture Format
To demonstrate this with an example, we’ll create and apply two formats, color and benefit on column HireDate.
Color format condition:
low-’31DEC2008’d= ‘light green’
’01JAN2009’d-high= ‘light red’;
Benefit format condition:
low-’31DEC2008’d= [worddate20.] /* write date in words */
’01JAN2009’d-high= ‘ ** Not Eligible **’;
Code that creates these two formats:
/* proc format with background colour & picture format*/
proc format library=work;
value benefit
low-'31DEC2008'd=[worddate20.]
'01JAN2009'd-high=' ** Not Eligible **';
value color
low-'31DEC2008'd='light green'
'01JAN2009'd-high='light red';
run;
Here is where we apply these two formats on hireDate column along with uscurrency format (which you have already created above in this article) on attribute Salary.
/* proc format picture with background colour */
proc print data=staff noobs label;
var name idnumber salary ;
var hiredate /style=[background=color.];
label salary='Salary in U.S. Dollars';
format salary uscurrency. hiredate benefit.;
title 'WORK.STAFF with a Format for the Variables';
title2 'Salary and HireDate';
run;
6. The SAS Picture Format for Big Amount
Here you’ll create a format that will handle how big amounts are displayed with currency prefix and adding M for millions, B for Billions, T for Trillions.
The amount will be rounded off for better representation.
/* sas proc format picture to display big amounts*/
proc format;
picture bigmoney (fuzz=0)
1E06-<1000000000='0000 M' (prefix='$' mult=.000001)
1E09-<1000000000000='0000 B' (prefix='$' mult=1E-09)
1E12-<1000000000000000='0000 T' (prefix='$' mult=1E-012);
run;
Now you need a data set where you have big amounts in one column. Let’s create with the do loop.
Here variable “i” is used to generate that big amount. Usually you don’t need to do this as you’ll have your own dataset with at least one column with a big amount. So you can just apply the picture format on it.
data mult;
do i=5 to 12;
bigAmount=16**i;
put bigAmount=comma20. bigAmount= bigmoney.;
fmtMoney=bigAmount;
output;
end;
format fmtMoney bigmoney.;
run;
proc print;
That’s all about Picture format in SAS. You can read this guide to learn more about SAS PROC FORMAT. We have covered all the details in this guide.
FAQ
It’s a concept to create structure or template to display or store data in specific format in SAS. The PROC FORMAT PICTURE procedure is used to create the picture formats in SAS.
To create a user-defined picture format, you can use the PROC FORMAT PICTURE procedure.
This procedure allows you to define a format name, specify the input values and their corresponding labels, and save the format for future use in data analyses and reporting