简体   繁体   English

SAS中的星期几功能

[英]Day of the week function in SAS

Is there an inbuilt function in SAS that gives the text day of the week? SAS中是否有内置功能可以提供星期几? Such as Monday, Tuesday etc from a date variable? 例如日期变量中的星期一,星期二等?

So far, I have just found the weekday function, that just gives the date as a number from 1-7. 到目前为止,我刚刚发现了工作日函数,该函数只将日期表示为1到7之间的一个数字。

If you want to get a text day of the week from a date, you can use DOWNAME. 如果要从日期获取星期几,可以使用DOWNAME。 format. 格式。

data _null_;
    result = put(today(), dowName.);
    put result=;
run;

If you want to get a weekday name from a weekday number, I do not know specific function, which does it, but you can use the fact that 1-7 are also dates and 0 is Friday, 1st January 1960 and add 2 to your number: 如果您想从工作日编号中获取工作日名称,我不知道具体的功能,但是您可以使用以下事实:1-7也是日期,0是1960年1月1日,星期五,然后将2加到数:

data _null_;
    do day = 1 to 7;
        weekDay = put(day + 2, dowName.);
        put weekDay=;
    end; 
run;

Which will give you: 这会给你:

 weekDay=Monday
 weekDay=Tuesday
 weekDay=Wednesday
 weekDay=Thursday
 weekDay=Friday
 weekDay=Saturday
 weekDay=Sunday

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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