0 Comments

May 16, 2020

SAS picture format creates templates in which you’ll be able to define how the numbers are displayed. With the use of PICTURE FORMAT, you will get over a number of display problems with numbers like:-

  1. Decimal and Comma Placement
  2. Embedding Characters with Numbers
  3. Prefixes

PICTURE statement in PROC FORMAT allows you to leverage the facility of PROC FORMAT. You could make labels look precisely the way you would like them to look.

A picture format works identically same as a primary format on the left-hand side (eg. the specification of ranges and values), the difference falls on the right-hand side (eg. the label display).

For the label display, there are three things to know,

  1. Using a ‘9’ (or any non-zero number) as a digit selector will drive the number to appear (i.e. will include leading zeros),
  2. Using a 0 as a digit selector will solely display the number if that digit is within the number (i.e. no leading zeros),
  3. Using a character string will display that character string precisely as included within the format.

One core rule for Picture Formats is that for those who use digit selectors as the template for displaying the data, the first position of the template has to be a digit selector. That
means you will be able to make the right parentheses as a part of the template itself since it’s clearly not a digit.

Instead, if you instruct PROC FORMAT to make the left parentheses the prefix to the template, which will begin with the (required) digit selector.

 proc format;
 picture phone_n (default=16)
 low-high = "999) 999-9999"
            (prefix='(')
            ;
 run;
 data Domestic_numbers;
 format phone phone_n.;
 input phone;
 datalines;
 5417543010
 ;
 run;

Picture-format

First, make the default length of the Picture Format 16 characters, which is broad enough to accommodate BOTH the template AND the required prefix. Give the prefix you like in the PREFIX option, that is just like the DEFAULT option is enclosed in parentheses.

Be cautious: The PREFIX option is within the parentheses, and the value of the option is a left parentheses symbol enclosed in single quotes.

CREATING A PICTURE FORMAT

1. CREATING A PICTURE FORMAT (APPENDING TEXT)

A textual content string might be added AFTER (however not BEFORE) the numbers by merely including the text within the format.

proc format;
 picture phone
 Low-high = '9999999999 - Mobile'
 ;
 run; 
 
 data test;
 format mobile phone.;
 input Mobile $30.;
 datalines;
 9900001000
 8888888888
 ;
 run;

6 Sas Picture Format Tips You Need To Learn Now 1


2. CREATING A PICTURE FORMAT (CHARACTER DISPLAY)

A character string might be displayed for certain values while displaying numbers for the other values. A format like this can be used:

proc format;
 picture temp
 low-36 = "Invalid Temperature"
 36.1-<37.2 = '99.00'
 37.2-high = '99.00 - High Body Temperature'
 ;
 run; 
 
 data testtemp;
 format temp temp.;
 input temp $30.;
 datalines;
 34.56
 13.45
 36.4
 36.8
 37.3
 38.0
 ;
 run;

Picture format
3. CREATING A PICTURE FORMAT (ROUND OPTION)

By default, when a picture format is applied, it truncates the data. (As a side note, by default when an existing SAS the format is applied like 5.1 or 7.3, the data is rounded.) In general, rounding is preferred to truncating.

To make a picture format round as an alternative of truncating, we merely add the ROUND option:

proc format;
 picture testA (round)
 Low-high = '000.00'
 ;
 run;
data _null_;
format val testA.;
input val;
put val=;
datalines;
3.1452342
2.96543
;
run;
 val=3.15
val=2.97


4. CREATING A PICTURE FORMAT (PREFIX OPTION)

With a picture format, character strings will be displayed after the digits as is shown in the above example.

Character strings can’t be displayed before the digits.

proc format;
	picture testB Low-<1000='099.00'
	1000-high='Value of 0000.00 too high'
	;
run;

data _null_;
	format val testb.;
	input val;
	put val=;
	datalines;
 3.1452342
 2899.96543
 ;
run;
val=03.14
val=2899.96 too high

Notice that the “Value of ” portion of the string is eliminated and the number seems to be formatted as indicated by the “0000.00” with the string “too high” appended to the end.

The PREFIX option will allow you to put a character string before the numbers. Replacing the code above with the following will fix the error and display the intended output:

proc format;
	picture testc Low-<1000='099.00'
	1000-high='0000.00 is too high' (prefix='Value of ')
	;
run;

data _null_;
	format val testc.;
	input val;
	put val=;
	datalines;
 3.1452342
 2899.96543
 ;
run;
val=03.14
val=Value of 2899.96 is too high


5. CREATING A PICTURE FORMAT (NOEDIT OPTION)

The NOEDIT option can be used to assist avoid some collisions with the data in the PICTURE format.

In the example below TESTd has, suppose as an alternative to “Value of 0000.00 is too high”, you want to show the text “Value >1000 is too high.” 

proc format;
	picture testd Low-<1000='099.00'
	1000-high='Value >1000 too high' (noedit)
	;
run;

data _null_;
	format val testd.;
	input val;
	put val=;
	datalines;
 3.1452342
 2899.96543
 ;
run;

related posts:


CALL SYMPUT in SAS – Explained


How to use the IN operator in SAS macro?


Exploring SAS Macro functions – eval and sysevalf

Subhro Kar

About the author

Been in the realm with the professionals of the IT industry. I am passionate about Coding, Blogging, Web Designing and deliver creative and useful content for a wide array of audience.

Subhro

Leave a Reply

Your email address will not be published. Required fields are marked

This site uses Akismet to reduce spam. Learn how your comment data is processed.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}