|
You have already taken the trouble to convert it to a numeric SAS date
value and have indicated that you want to keep the 2 calculated variables
also numeric. Why not keep all of them as SAS date numeric variables and
then calculate the next and previous days using the SAS date functions.
Finally, you can display them in whatever date format you want by assigning
the appropriate date formats. By the way, I think you want the yymmddn8
format. Perhaps you didn't realize it was there to give you what you want:
data four ;
set one ;
_aaa=input(put(aa, 8.), yymmdd10.);
next_day = intnx('day',_aaa,1) ;
prev_day = intnx('day',_aaa,-1) ;
format _aaa next_day prev_day yymmddn8. ;
run ;
proc print ;
run ;
Obs aa _aaa next_day prev_day
1 20031201 20031201 20031202 20031130
2 20040131 20040131 20040201 20040130
3 20041231 20041231 20050101 20041230
4 19610101 19610101 19610102 19601231
5 19020131 19020131 19020201 19020130
Kind Regards,
Venky Chakravarthy
On Mon, 10 May 2004 11:53:18 -0400, Chen, Jian <ozz6@CDC.GOV> wrote:
>SAS-user:
>
>The following codes that I wrote read in aa as a numeric. I wanted next
>day and previous day of aa, and output prev_day and next_day also as
>numeric. The codes work, but I think the codes in data four step can be
>shortened. Anyone has good ideas?
>
>
>data one;
>input aa ;
>cards;
>20031201
>20040131
>20041231
>19610101
>19020131
>;
>
>data four(drop=_:);
>set one;
>_aaa=input(put(aa, 8.), yymmdd10.);
>
>_prev_day=_aaa-1;
>_bb1=put(_prev_day, yymmdd10.);
>_prev_day_=compress(_bb1, '-');
>prev_day=input(_prev_day_, 12.);
>
>_next_day=_aaa+1;
>_bb2=put(_next_day, yymmdd10.);
>_next_day_=compress(_bb2, '-');
>next_day=input(_next_day_, 12.);
>run;
>
>Output:
>
>
>
> Obs aa prev_day next_day
>
> 1 20031201 20031130 20031202
> 2 20040131 20040130 20040201
> 3 20041231 20041230 20050101
> 4 19610101 19601231 19610102
> 5 19020131 19020130 19020201
|