数学之路-sas备忘(14)

来源:互联网 发布:淘宝联盟买家已收货 编辑:程序博客网 时间:2024/05/19 16:05

sas日期格式


data _null_;

     x='7jan2012'd;
     put x yymm7.;
     put x yymmc7.;
     put x yymmd7.;
     put x yymmn6.;
     put x yymmp7.;
     put x yymms7.;
     put x yymon7.;
put x mmddyy10.;
put x yymmdd10.;

run;


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

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

2012M01
2012:01
2012-01
201201
2012.01
2012/01
2012JAN
01/07/2012
2012-01-07

SAS中用数值来表示日期,SAS日期值等于具体日期离1960/1/1天数。

比如:


 date            SAS value   


1959-1-1      -365


1960-1-1         0


1961-1-1         365


2008-1-1       17532

日期输入与输出格式

data x12;
input date1:yymmdd10. date2:yymmdd10.;
format date1:yymmdd10. date2:yymmdd10.;
days1=datdif(date1,date2,'act/act');/*按实际*/
days2=datdif(date1,date2,'30/60');/*每个月30天*/
datalines;
2015-01-01 2015-02-14
2014-05-25 2014-06-21
;


proc print ;

run;




data x110;
input date1:anydtdte. date2:anydtdte.;
format date1:yymmdd10. date2:yymmdd10.;
days1=datdif(date1,date2,'act/act');/*按实际*/
days2=datdif(date1,date2,'30/60');/*每个月30天*/
datalines;
2015-01-01 2015-02-14
2014-05-25 2014-06-21
;


proc print ;
title "anydtdte";
run;


相差年数
data x_1;
input date1:anydtdte. date2:anydtdte.;
format date1:yymmdd10. date2:yymmdd10.;
days1=yrdif(date1,date2,'act/act');/*按实际*/
days2=yrdif(date1,date2,'30/60');/*每个月30天*/
datalines;
2013-01-01 2015-02-14
2014-05-25 2015-03-21
;
proc print ;
title "year";
run;


data _null_;
input date DATETIME20. ;
put "----不同日期时间格式----";
put date DATETIME18. ;
put date DATETIME20. ;
put date DATETIME15. ;
put date DATETIME12. ;
datalines;
13SEP2008:02:35:43
;
run;

Labels and Formats Window

Use the Labels and Formats window to specify labels, widths, and formats for displaying variables in the application. The window contains the following items:

Variable

lists the variables for which you can customize labels and formats. This includes analysis and drill variables. You can add or delete variables by going to the corresponding variable selection windows.

Type

lists the data type for the corresponding variable, as specified in the data set.

N

stands for numeric.

C

stands for character.

Default

type any character other than blank into the field. That value is converted to X. When the Default flag is set, values for labels and formats are read from the repository at run time. If the flag is not set, values specified here are used.

Label

enter a label up to 30 characters long for each variable. Default labels are taken from the repository.

If the Default flag is set, the labels are taken directly from the repository at run time.

Format

enter a format for displaying the variable's values in the report. The format type must match the variable type as shown in the Variable column. The field is initialized with the format from the repository.

You can enter a question mark (?) as the first character in the field to display a list of valid formats.

If the Default flag is set, the formats are taken directly from the repository at run time.

Width

specifies a column width for displaying values of the corresponding variable in the report.

The default width is determined by analyzing the current format. If that is not possible (for example, for user-written character formats), the length of the variable is used. Field width must not be smaller than the width of the formatted values, but it can be larger, for example, to create room for long labels.

Reset

returns all values to the default values specified in the repository.


1 0
原创粉丝点击