Date calculations in SAS

前端 未结 3 1336
轮回少年
轮回少年 2020-12-06 09:16

I want to add 1 day to an arbitrary SAS date. I have the following code that works but I wonder wether there is built-in support for date calculations like this:

<         


        
3条回答
  •  余生分开走
    2020-12-06 09:24

    In SAS, there's no DATE or DATETIME data type, such values are stored as generic Numeric data type, where for date: the number stored represents number of days between date represented and January 1st 1960. For datetime it's similar, only number of seconds is stored. You'll see this in code below. Human readable date, time and datetime representation is achieved via SAS date/time formats. For further explanation just do a search on SAS dates on web and documentation.

    Back to you're question: to add one day to a value representing DATE, just do a mathematical addition: +1.

    data _null_;
        length mydate mydatetime 8;
        mydate='1jan1960'd;
        mydatetime='1jan1960:00:00:00'dt;
        nextdate = mydate + 1;
        nextminute = mydatetime + 60;
        put mydate 8. +4 mydate yymmdds10.;
        put nextdate 8. +4 nextdate yymmdds10.;
        put mydatetime 12. +4 mydatetime datetime.;
        put nextminute 12. +4 nextminute datetime.;
    run;
    

提交回复
热议问题