SAS: formats/informats/types. Their differences

12,647

Solution 1

In SAS, variables have two possible types: character or numeric.

Informat is similar but a little different. It controls how SAS read data from external data sources. There are three variants, numeric, character and date/time. Citing the code you provide here, informat=ddmmyy16. tells SAS to read input data in a date/time format. 16 is the width. There are many informat, conditioning on like length, decimals etc.

And also, are dates (__ToDate, __FromDate ) have a numeric type? (their missing value is dot ., not quotes "")?

In SAS, missing value of character type is given double quote "". For numeric type, it is dot .. Date/time is regarded as a numeric type.

Solution 2

An informat is an instruction that SAS uses to read data values into a variable. (INFORMAT Statement)

Informats are typically used to read or input data from external files called flat files (text files, ASCII files, or sequential files). You can also use informats in an INPUT function within a DATA step. The informat instructs SAS on how to read data into SAS variables. (Introduction to SAS Informats and Formats)

In SAS there are only two types of variables - Character and Numeric. However, a variable can be assigned any one of many INFORMATS. I don't believe an INFORMAT is relevant unless an INPUT statement/function is being used.

Solution 3

One additional comment about INFORMATS; they are also used with interactive tools that access the dataset (in particular the VIEWTABLE application, which lets one edit a dataset from inside a SAS session).

For example, suppose your variable is defined with an INFORMAT of "date9." and a FORMAT of "mmddyy10.". If you use VIEWTABLE to edit the dataset and type "18apr2012" in the column, SAS will accept that as a date and display it as "04/18/2012".

Just rememner that INFORMATS and FORMATS are different "attributes" of a SAS variable and can be modified any time. FORMATS can also be "overridden" by vaious procedures with a FORMAT statement.

Share:
12,647
gaussblurinc
Author by

gaussblurinc

interesting in: C++, C#, Perl, Statistics and Time Series theory. LinkedIn: https://ru.linkedin.com/in/dmitry-lobanov-49b65278

Updated on July 16, 2022

Comments

  • gaussblurinc
    gaussblurinc almost 2 years

    another question about formats and informats:

    formats are using for output (for show me and other user data in tables), so, i don't care about it, if i want read data from tables in programming way, yes?

    but what is informat?

    i have data step with code like this:

     data Out; 
           attrib __fromDate __ToDate informat=ddmmyy16. format=worddatx32.
                  __name __country length = $10
           ;
    
     set InputTab;
    
     /*see Dates*/
     retain __fromDate .;
     retain __ToDate .; 
    
    /*see Strings*/
     retain __name "";
     retain __country "";
    
     __fromDate=coalesce(__fromDate,fromDate);
     __ToDate=coalesce(__fromDate,fromDate);
     __name=coalescec(__name,name);
     __country=coalescec(__country,country);
    
    run;     
    

    Does this code work and what type have all these vars on each statement?

    Am i right, that informat and type of var are similar?

    And also, are dates (__ToDate, __FromDate ) have a numeric type? (their missing value is dot ., not quotes "")?

    Thank you!

  • Robert Penridge
    Robert Penridge about 12 years
    I disagree with the statement that there are three variants of informat (numeric, char, and datetime). There's really just informats that create numerics, and informats that create char variables. I could create a character variable based on importing a numeric value (e.g. 3 -> Three), or a numeric variable based on applying an informat to a character string (e.g. Three -> 3). The informat simply determines what format the input source must be in (whether it be a string or a numeric) in order for it to import successfully. In SAS, dates and times are simply stored as numeric vars.
  • Robbie Liu
    Robbie Liu about 12 years
    It's true that dates and times are stored as numeric vars in SAS. As I mentioned, they share the same type. However, date/time informat takes different forms from numeric vars do. For example, a typical numerical informat is comma10.2 which controls both the width of integer (10) and decimal part (2), but for date/time, informat is like mmddyy10., completely different. Refer support.sas.com/publishing/pubcat/chaps/59498.pdf for more detail.
  • Robert Penridge
    Robert Penridge about 12 years
    I agree with everything in your comments but I think perhaps you misunderstood the point I'm trying to make. My point is that an informat simply tells SAS how to parse a string in order to convert it to a SAS variable. There's simply informats. For example I can create a single informat that reads in strings, numerics, and dates, and converts them all to some value of my choice. Eg. invalue trial 'A'-'M'=1 'N'-'Z'=2 1-3000=3;