Hello SAS Community,
I am using SAS 9.4 (English). For my dataset, I am seeing different attributes for Format and Informat for some variables according to whether I look at the attributes in the Results Viewer (after running proc contents) or the Explorer (the column attributes of VIEWTABLE: Work.dataset). Here are two examples:
variable1:
variable2:
Could someone please explain why this could be happening?
Thank you for your help.
Tristan
Permanently attached FORMAT or INFORMAT are not required for variables in SAS datasets. If there is no format attached to numeric variable SAS will print it using BEST12. If there is no format attached to a character variable then SAS will print it using $w. where W is the length of the variable.
data x ;
length var1 $8 var2 8 ;
format var3 5. ;
informat var4 $12. ;
run;
proc contents data=x ; run;
It looks like the VIEWTABLE is trying populate the empty values with values that represent what format you want to attach to replicate the default SAS behavior. Not sure why it uses 5. for the INFORMAT for VAR3, but if you are using list mode input (eg INPUT var1 var2 var3 var4; ) then SAS will ignore the widths of the INFORMATs that are attached to the variables anyway and adjust the width to the width of the actual value in the input stream.
Permanently attached FORMAT or INFORMAT are not required for variables in SAS datasets. If there is no format attached to numeric variable SAS will print it using BEST12. If there is no format attached to a character variable then SAS will print it using $w. where W is the length of the variable.
data x ;
length var1 $8 var2 8 ;
format var3 5. ;
informat var4 $12. ;
run;
proc contents data=x ; run;
It looks like the VIEWTABLE is trying populate the empty values with values that represent what format you want to attach to replicate the default SAS behavior. Not sure why it uses 5. for the INFORMAT for VAR3, but if you are using list mode input (eg INPUT var1 var2 var3 var4; ) then SAS will ignore the widths of the INFORMATs that are attached to the variables anyway and adjust the width to the width of the actual value in the input stream.
Hi Tom,
Thanks for your quick reply. I appreciate it.
Tristan
proc contents report includes colomn of varyable type, therefore the format is just the length of the variable unless defined explicitly.
variable1 is caharacter type. Viewtable assigns $ as prefix to length to say it is char type.
variable2 is numeric. If format/informat are not defined, proc contents will display blank attribute,
while viewtable displayes the default attributes.
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.