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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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