简体   繁体   中英

How to calculate month number in sas

Hi I need to calculate the value of month supposed in sas 01jan1960 is equal to 1 02jan1960 is equal to 2

So I need to calculate for 01aug2020 I used intck function but no output

I want in datastep only .

SAS stores dates as the number of days since 1960 with zero representing first day of 1960. To represent a date in a program just use a quoted string followed by the letter D. The string needs to be something the DATE informat can interpret.

Let's run a little test.

6     data _null_;
7       do dt=0 to 3,"01-JAN-1960"d,'01AUG2020'd;
8         put dt= +1 dt date9.;
9       end;
10    run;

dt=0  01JAN1960
dt=1  02JAN1960
dt=2  03JAN1960
dt=3  04JAN1960
dt=0  01JAN1960
dt=22128  01AUG2020

So the date value for '01AUG2020'd is 22,128.

Subtraction works

days_interval = '01Aug2020'd - '01Jan1960'd;

Or looking at the unformatted value as SAS stores dates from 01Jan1960

days_interval = '01Aug2020'd;
format days_interval 8.;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM