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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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