SAS Formats convert either numeric or character values to character values. A format can either be applied using a format
or put
statement, which changes the way a value is displayed, or using the put
function to store the formatted value in a new variable.
There are four categories of formats :
Formats usually take the form <formatname><w>.<d>;
, w
being the width (including any decimals and the point), d
being the number of decimal places.
Common date formats (applied to SAS date values) :
date9.
e.g. 02AUG2016ddmmyyn8.
e.g. 02082016ddmmyy8.
e.g. 02/08/16yymmdd10.
e.g. 20160802year4.
e.g. 2016Common numeric formats (applied to numbers) :
comma11.0
e.g. 1,234,567comma12.2
e.g. 1,234,567.00dollar11.2
e.g. $5,789.12nlmnlgbp11.2
e.g. £2,468.02Other formats :
$hex8.
, convert string to hex$upcase.
, convert string to upper-case$quote.
, enclose a string in quotesA full list of formats can be found here > https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001263753.htm
Labels can be used to describe a variable which helps improve the readability of your outputs. Labels can be permanently created in the DATA
step or temporarily created in a PROC
step.
More information on the %BQUOTE function can be found here: https://v8doc.sas.com/sashtml/macro/z4bquote.htm
Informats are very important especially when we import data from other datasets. For example, most of the times while working on real time data, we extract data from various data sources (Oracle,Mysql,Teradata etc). Every time we import data we need to specify the informat statement so SAS can read the data properly.
As mentioned in the introduction, we can also use Merge
inside a data step
which will be discussed under a separate topic. Joins play a very important role to blend and unify data according to the requirement.