the format of a numeric variable can be
format score comma10.2;
format capital dollar8.2;
the format of a date is
format sdate date9.;
format today_date MMDDYY10.,
format a string variable:
format gender $genderf. average_score label.; /*genderf and label defined in the libname*/
when a period should be added to the format (a date or string variable, anything else?) and when is a period unnecessary (only like a numeric variable?)?
A dot is always required when using a format. Notice all the formats you listed in your example contain a dot somewhere. The dot might not appear at the end, but it always appears somewhere.
When creating your own format using PROC FORMAT, the dot is not needed as part of the format name. Only when you later use the format is the dot required.
Some programmers add a dot in a LENGTH statement, such as:
length gender $1.;
The LENGTH statement never requires a dot. If you add one, SAS will forgive you, but it is not needed.
A dot is always required when using a format. Notice all the formats you listed in your example contain a dot somewhere. The dot might not appear at the end, but it always appears somewhere.
When creating your own format using PROC FORMAT, the dot is not needed as part of the format name. Only when you later use the format is the dot required.
Some programmers add a dot in a LENGTH statement, such as:
length gender $1.;
The LENGTH statement never requires a dot. If you add one, SAS will forgive you, but it is not needed.
thanks!
A period is needed with FORMAT statement for all data types.
A FORMAT statement always requires a period, so something in this format:
format variableName formatName.;
You can have something after the period as well, for numeric formats at least.
And the exception to the rule, is when passing formats using PUTN() or PUTC() where the format can be just the string, no period, otherwise a period is usually required.
is a character format that you want to apply to value.
Here are valid format forms:
You need to include a period in your format specification so the compiler knows you mean a format and not variable name.
In your code examples you are using the format specifications of
comma10.2 dollar8.2 date9. MMDDYY10. $genderf.
Which are references to the formats named COMMA, DOLLAR, DATE, MMDDYY and $GENDERF.
If you removed the period from the format specification then it looks like a variable name. So this statement is attaching the DOLLAR format with a width of 8 characters of which 5 are before the decimal point and 2 after.
format capital dollar8.2;
But this statement is removing the formats from two variables named capital and dollar82 .
format capital dollar82;
The digits after a dot in a format indicate how many decimal values to display. So really only applicable for numeric formats.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.