Reputation: 86
In the following sas codes..
data temp2;
input id 1 @3 date mmddyy11.;
cards;
1 11/12/1980
2 10/20/1996
3 12/21/1999
;
run;
proc print data = temp2;
format date date9.;
run;
Rsults in :
id date
1 12NOV1980
2 20OCT1996
3 21DEC1999
Consider the following output and date type:
data temp3a;
set temp2;
two_days = intnx('day',date,2);
run;
proc print data = temp3a noobs;
format date two_days date9.;
run;
Result
id date two_days
1 12NOV1980 14NOV1980
2 20OCT1996 22OCT1996
3 21DEC1999 23DEC1999
What I want is that the output date should be in the following format:
id date two_days
1 12NOV80 14NOV80
2 20OCT96 22OCT96
3 21DEC99 23DEC99
Also when I perform the following:
data have01211;
set WORK.XX;
two_days_before = intnx('day', Date, -2);
two_days_after = intnx('day', Date, 2);
run;
proc print data = have01211 noobs;
format two_days_before two_days_after date8.;
run;
The result i get is as follows:
two_days_before two_days_after
20764 20768
20758 20762
20763 20767
20730 20734
Why this?? Why not same format as in original data?
Upvotes: 1
Views: 79
Reputation: 12691
Regarding your first question - just modify the format as follows:
data temp3a;
set temp2;
two_days = intnx('day',date,2);
run;
proc print data = temp3a noobs;
format date two_days date8.; /* shorter date format length */
run;
Regarding the second question - you are applying the format in the proc print
but not the dataset (am presuming you are talking about have01211
). Simply attach a format to those variables in the data step as follows:
data have01211;
set WORK.temp2;
two_days_before = intnx('day', Date, -2);
two_days_after = intnx('day', Date, 2);
format two_days_before two_days_after date8.;
run;
Explanation - when you apply a format in a proc print, it only applies to that print step. If you add a format when creating a dataset, it is stored permanently with that dataset - so in fact you won't need a format statement in any subsequent proc print
's:
proc print data = have01211 noobs;
run;
Upvotes: 1