BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TristanJ
Fluorite | Level 6

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

4 REPLIES 4
Tom
Super User Tom
Super User

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.

 

 

TristanJ
Fluorite | Level 6

Hi Tom,

 

Thanks for your quick reply. I appreciate it.

 

Tristan

Shmuel
Garnet | Level 18

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. 

TristanJ
Fluorite | Level 6
Shmuel,

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

Tristan

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
  • 4 replies
  • 1497 views
  • 0 likes
  • 3 in conversation