is proc format permanent?
when do you use format statement in data step? do you have to define a variable's format if its length is greater than 8?
@clqa wrote:
is proc format permanent?
Is any code permanent?
when do you use format statement in data step?
You use formats whenever you want the value of the variable to appear in a way that is defined by the format.
do you have to define a variable's format if its length is greater than 8?
Variables whose length is greater than 8 do not have to have a format.
@clqa wrote:
is proc format permanent?
Yes, no and maybe.
A format can be permanently assigned to a variable. Typically in a data step but other procedures can do so. Proc DATASETS is intended to change characteristics of a data set such as variable formats, variable names, variable labels as some other things. Most procedures that produce output sets involving the formatted value of a variable will have that format "permanently" assigned in the output set even though it wasn't in the input.
While the format may be permanently assigned to a variable the format itself might be temporary. You can create custom formats with proc format. Default will place the format definition in the WORK library. So a permanent data set with such a format may not find the format definition if the format code isn't run in the next SAS session. There are options with Proc Format to write the format definitions to a library and then tell SAS to find the definitions in that location.
A format can also be used temporarily for specific output at need. For example run this example and see the difference in the output.
The SASHELP.CLASS data set should be included in your installation.
Proc freq data=sashelp.class; title "Default format"; tables height; run; Proc freq data=sashelp.class; title "Assigned F2 Format"; tables height; format height f2.; run;title;
@ballardw wrote:
@clqa wrote:
is proc format permanent?
A format can be permanently assigned to a variable. Typically in a data step but other procedures can do so. Proc DATASETS is intended to change characteristics of a data set such as variable formats, variable names, variable labels as some other things.
... but the format can be "un-assigned" in the next data step or next PROC. Permanence is not guaranteed.
@clqa wrote:
is proc format permanent?
Well, it's been there for as long as I've been using SAS, so I guess, yes.
@clqa wrote:
do you have to define a variable's format if its length is greater than 8?
NO
Only character variables can have a storage length greater than 8. And SAS does not need to have a format attached to a character variable to know how to display it.
In fact most variables do not need to have formats attached to them.
If you are using DATE/TIME/DATETIME values then you will want to attach a format to make the readable. If you have really large numbers you might want to use the COMMA format to make them easier to read. If you have non-integer values you might want to use a format to fix the number of decimal places that are displayed.
Some people seem to think that
format longvar $50. ;
Is a way to define longvar as a character variable of length 50 bytes. But that would only happen if that was the first place that the variable was defined. Then SAS would guess that you meant to define it with a length of 50 because you attached a format with a width of 50 to it. If you really want to define the length use a LENGTH statement (or the LENGTH= attribute of the ATTRIB statement).
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!
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.