Search code examples
formatsasinformat

format and informat in sas


I have the following data:

data d;
input date1 $ date2 $;
cards;
5oct10  11nov11
6jul12  12oct13
1jan08  4may10
4may04  8jul06
1mar07  5aug07
18may04 1oug09
7aug05  8jul09
1feb03  5apr06
3feb01  15jul08
4apr07 16apr07
run;

*I need to read this in a date7.informat and then present the data on date9.format.

*how do I do I read the data to begin with on a width format, and how do I convert the date's width from 7 to 9 while my cars are not completely numeric?

when trying something like that:

proc print data=d;
format date1 date2 date9.;;
run;

it fails since I use a numeric format on a none-completely numeric var


Solution

  • If you use an INFORMAT statement to tell SAS how to read the variables then you do not not need to list a format in the INPUT statement. The INFORMAT and the FORMAT for a variable do not need to be the same, but in this case they can be because the DATE9 informat will recognize a value with only a two digit year.

    informat date1 date2 date9.;
    format date1 date2 date9.;
    input date1 date2 ;