Format and Informat differ b/w Results Viewer (proc contents) and Explorer (VIEWTABLE: Work.dataset)

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Format and Informat differ b/w Results Viewer (proc contents) and Explorer (VIEWTABLE: Work.dataset)

[ Edited ]

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:

  • Results Viewer: Format = 8., Informat = 8.
  • Explorer: Format = $8., Informat = $8.

variable2:

  • Results Viewer: Format = (it is blank), Informat = (it is blank)
  • Explorer: Format = BEST12., Informat = 12.

 

Could someone please explain why this could be happening?

 

Thank you for your help.

 

Tristan

 

 


Accepted Solutions
Solution
4 weeks ago
Super User
Super User
Posts: 6,326

Re: Format and Informat differ b/w Results Viewer (proc contents) and Explorer (VIEWTABLE: Work.data

[ Edited ]

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;

Capture.PNG

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.

 

 

View solution in original post


All Replies
Solution
4 weeks ago
Super User
Super User
Posts: 6,326

Re: Format and Informat differ b/w Results Viewer (proc contents) and Explorer (VIEWTABLE: Work.data

[ Edited ]

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;

Capture.PNG

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.

 

 

Occasional Contributor
Posts: 8

Re: Format and Informat differ b/w Results Viewer (proc contents) and Explorer (VIEWTABLE: Work.data

Hi Tom,

 

Thanks for your quick reply. I appreciate it.

 

Tristan

Super User
Posts: 1,230

Re: Format and Informat differ b/w Results Viewer (proc contents) and Explorer (VIEWTABLE: Work.data

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. 

Occasional Contributor
Posts: 8

Re: Format and Informat differ b/w Results Viewer (proc contents) and Explorer (VIEWTABLE: Work.data

Shmuel,

Thank you for your reply. It, along with Tom's reply, is helpful.

Tristan
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 89 views
  • 0 likes
  • 3 in conversation