IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    [原]数学之路-sas备忘(16)

    u010255642发表于 2015-03-30 12:06:50
    love 0

    SAS日期及时间格式

    data _null_;
    mydate ='7MAR13'd;
    put mydate YYMMDDP10.;
    put mydate YYMMDDN8.;
    put mydate YYMMDDC10.;
    put mydate YYMMDDS10.;
    put mydate YYMMDD10.;
    put mydate WEEKDATE.;
    put mydate WORDDATE.;
    run;


    本博客所有内容是原创,如果转载请注明来源

    http://blog.csdn.net/myhaspl/


    2013.03.07
    20130307
    2013:03:07
    2013/03/07
    2013-03-07
    Thursday, March 7, 2013
    March 7, 2013
    NOTE: “DATA 语句”所用时间(总处理时间):
    实际时间 0.01 秒
    CPU 时间 0.01 秒

    ==============

    data _null_;
    mytime ='17:25:38't;
    put mytime HHMM.;
    put mytime TIME.;
    put mytime TIMEAMPM.;
    put mytime HOUR.;
    put mytime TOD.;
    run;





    17:26
    17:25:38
    5:25:38 PM
    17
    17:25:38


    data _null_;
    now=datetime();
    put now DATEAMPM.;
    put now DATETIME.;
    put now nldatm.;
    run;


    30MAR15:03:12:14 PM
    30MAR15:15:12:14
    2015年03月30日 15时12分14秒



    data _null_;
    now=date();
    put now YEAR.;
    put now MONTH.;
    put now DAY.;
    run;

    2015
    3
    30
    NOTE: “DATA 语句”所用时间(总处理时间):
    实际时间 0.00 秒
    CPU 时间 0.00 秒


    data _null_;
    /*当前日期及时间*/
    now=date();
    put now YEAR.;
    put now MONTH.;
    put now DAY.;
    put now=nldate.;
    t1=time();
    put t1=time.;
    put t1=nltimap15.;
    d1=today();
    put d1=nldate.;
    d2=today();
    put d2=nldate.;


    run;


    2015
    3
    30
    now=2015年03月30日
    t1=15:21:50
    t1=下午03:21:50
    d1=2015年03月30日
    d2=2015年03月30日
    NOTE: “DATA 语句”所用时间(总处理时间):
    实际时间 0.01 秒
    CPU 时间 0.01 秒


    Writes datetime values in the form ddmmmyy:hh:mm:ss.ss.

    Category:Date and Time
    Alignment:Right
    Restriction:If w–d< 17, SAS truncates the decimal values.
    Interaction:When the DECIMALCONV= system option is set to STDIEEE, the output that is written using this format might differ slightly from previous releases. For more information, see DECIMALCONV= System Option in SAS System Options: Reference.

    Syntax

    DATETIMEw.d

    Syntax Description

    w

    specifies the width of the output field.

    Default16
    Range7–40
    TipSAS requires a minimum w value of 16 to write a SAS datetime value with the date, hour, and seconds. Add an additional two places to w and a value to d to return values with optional decimal fractions of seconds.

    d

    specifies the number of digits to the right of the decimal point in the seconds value. This argument is optional.

    Range0–39
    Requirementmust be less than w

    Details

    The DATETIMEw.d format writes SAS datetime values in the form ddmmmyy:hh:mm:ss.ss:
    dd
    is an integer that represents the day of the month.
    mmm
    is the first three letters of the month name.
    yy
    is a two-digit integer that represents the year.
    hh
    is an integer that represents the hour in 24–hour clock time.
    mm
    is an integer that represents the minutes.
    ss.ss
    is the number of seconds to two decimal places.

    Example

    The example table uses the input value of 1668138559, which is the SAS datetime value that corresponds to 3:49:19 a.m. on November 10, 2012.
    SAS Statement
    Result
    ----+----1----+----2----+
    put event datetime.;
    10NOV12:03:49:19
    put event datetime7.;
    10NOV12
    put event datetime12.;
      10NOV12:03
    put event datetime18.;
      10NOV12:03:49:19
    put event datetime18.1;
    10NOV12:03:49:19.0
    put event datetime19.;
     10NOV2012:03:49:19
    put event datetime20.1;
    10NOV2012:03:49:19.0
    put event datetime21.2;
    10NOV2012:03:49:19.00
    ============================
    data _null_;
    /*当前日期及时间
    *datetime基本格式*
    */


    mydt=datetime();
    put mydt datetime21.2;*2为定要在秒值小数点右边的位数。;
    put mydt datetime.;
    put mydt datetime7.;
    put mydt datetime12.;
    put mydt datetime18.;
    put mydt datetime18.1;
    put mydt datetime19.;
    put mydt datetime20.1;

    run;


    30MAR2015:17:25:51.91
    30MAR15:17:25:52
    30MAR15
    30MAR15:17
    30MAR15:17:25:52
    30MAR15:17:25:51.9
    30MAR2015:17:25:52
    30MAR2015:17:25:51.9
    NOTE: “DATA 语句”所用时间(总处理时间):
    实际时间 0.01 秒
    CPU 时间 0.00 秒

    ===============

    DATETIMEw. Informat


    Syntax

    DATETIMEw.

    Syntax Description

    w

    specifies the width of the input field.

    Default18
    Range13–40

    Details

    The datetime values must be in the following form: ddmmmyy or ddmmmyyyy, followed by a blank or special character, followed by hh:mm:ss.ss (the time):
    dd
    is an integer between 01 and 31 that represents the day of the month.
    mmm
    is the first three letters of the month name.
    yy or yyyy
    is a two-digit or four-digit integer that represents the year.
    hh
    is an integer between 00 and 23 that represents hours.
    mm
    is an integer between 00 and 59 that represents minutes.
    ss.ss
    is the number of seconds ranging from 00–59 with the fraction of a second following the decimal point.
    DATETIMEw. requires values for both the date and the time. However, the ss.ss portion is optional.
    Note: SAS interprets a two-digit year as belonging to the 100-year span that is defined by the YEARCUTOFF= system option.
    Note: SAS can read time values with AM and PM in them.

    Comparisons

    The DATETIMEw.d informat reads datetime values with optional separators in the form dd-mmm-yy hh:mm:ss.ss AM|PM, and the date and time can be separated by a special character.
    The MDYAMPMw.d in format reads datetime values with optional separators in the form mm-dd-yy hh:mm:ss.ss AM | PM, and requires a space between the date and the time.
    The YMDDTTMw.d informat reads datetime values with required separators in the form yy-mm-dd/hh:mm:ss.ss.

    Example

    input date_and_time datetime20.;
    Data Line
    Result
    ----+----1----+----2
    16mar12:11:23:07.4
    1647516187.4
    16mar2012/11:23:07.4
    1647516187.4
    16mar2012/11:23 PM
    1647559380.0

    ===========
    data x11;
    /*
    *datetime输入与输出格式*
    */
    input mydate YMDDTTM21.2;
    format mydate datetime21.2;
    cards;
    2015-05-15/15:28:19.2
    ;
    proc print;
    run;


    Writes SAS date values in the form <yy>yymmdd or <yy>yy–mm–dd, where a hyphen is the separator and the year appears as either 2 or 4 digits.

    YYMMDDw.

    Arguments

    w

    specifies the width of the output field.

    Default8
    Range2–10
    InteractionWhen w has a value of from 2 to 5, the date appears with as much of the year and the month as possible. When w is 7, the date appears as a two-digit year without hyphens.

    Details

    The YYMMDDw. format writes SAS date values in the form <yy>yymmdd or <yy>yy–mm–dd. Here is an explanation of the syntax:
    <yy>yy
    is a two-digit or four-digit integer that represents the year.
    –
    is the separator.
    mm
    is an integer that represents the month.
    dd
    is an integer that represents the day of the month.

    Comparisons

    • The YYMMDDw.d format is similar to the YYMMDDxw.d format, except the YYMMDDxw.d format contains separators, such as a colon, slash, or period between the year, month, and day.

    Example

    The following examples use the input value of 18720, which is the SAS date value that corresponds to April 3, 2011.
    Statements
    Results
     
    ----+----1----+
    a=put(18720,yymmdd2.);
    11
    a=put(18720,yymmdd3.);
    11
    a=put(18720,yymmdd4.);
    1104
    a=put(18720,yymmdd5.);
    11-04
    a=put(18720,yymmdd6.);
    110403
    a=put(18720,yymmdd7.);
    110403
    a=put(18720,yymmdd8.);
    11-04-03
    a=put(18720,yymmdd10.);
    2011-04-03
    ========================
    data x11;
    input mydate1:YYMMDD10. mydate2:YYMMDD7.;
    format mydate1:YYMMDDN8. mydate2:YYMMDD8.;
    cards;
    20140515 150205
    ;
    proc print;
    run;

    data x19;
    input mydate1:YYMMDD10. mydate2:YYMMDD7.;
    format mydate1:YYMMDDN8. mydate2:YYMMDD8.;
    cards;
    2014-05-18 150205
    ;
    proc print;
    run;




沪ICP备19023445号-2号
友情链接