BookmarkSubscribeRSS Feed
clqa
Calcite | Level 5

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?

5 REPLIES 5
PaigeMiller
Diamond | Level 26

@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.

 

 

--
Paige Miller
ballardw
Super User

@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;
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
Tom
Super User Tom
Super User

@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).

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 978 views
  • 0 likes
  • 5 in conversation