Reputation: 317
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
Upvotes: 0
Views: 745
Reputation: 51611
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 ;
Upvotes: 0
Reputation: 336
Modify your data step such that:
input date1 date7. date2 date7.;
If you use date1 $
to read the datelines, your resulted dataset would have the value for date1 = '5oct10','6jul12' and so on
. However, when you apply the format date9.
at proc print
, you need to supply a SAS time value. Please note that SAS read time value in its own format i.e. counting from 01/Jan/1960. You could try it by running the statement `put "today is today()" at your SAS.
And your proc print statement should work perfectly after the modification.
And, for some reason(s) you want to read the value of date1 and date2 in its own format i.e. 5oct10
, I am afraid you may need to separate the value day, month, and year respectively( e.g. by scan
function) and use the function MDY( month, day, year)
to turn it into a SAS time value. Your format statement with date7.
at proc print
statement would also work in this case.
Upvotes: 0
Reputation: 4554
data d;
input date1 date7. date2 date7.;
format date1 date9. date2 date9.;
cards;
5oct10 11nov11
6jul12 12oct13
1jan08 4may10
4may04 8jul06
1mar07 5aug07
18may04 1oug09
7aug05 8jul09
1feb03 5apr06
3feb01 15jul08
4apr07 16apr07
;
run;
Upvotes: 1