全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
3818 4
2006-06-08

请教各位了,SAS中的日期数据比如,2004-04-15,应该怎样转换为数值型的20040415?多谢了

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2006-6-8 19:09:00
先提取,再合并,如year(x),month(x),date(x),
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2007-2-17 03:49:00

***1.Use informat to read in your data, so sas can understand it is a date value.

***2.sas stores this variable x as a numeric number, this number means how many day after 1960-1-1, the day SAS company was started.

***3.But if you don't use format, it won't print out like a data value '20040415'.

***4.There is 6 different yymmdd formats can help you to print x variable:

yymmddb10. It means 'space', 2004 4 15

yymmddc10. It means 'colon', 2004:4:15

yymmddd10. It means 'hyphen', 2004-4-15 (This is default, it is the same as mmddyy10.)

yymmddn10. It means 'none' 20040415

yymmddp10. It means 'period' 2004.4.15

yymmdds10. It means 'slash' 2004/4/15

***5.You can also use other formats like: mmddyy10., mmddyy8., yymmn4., yyq4. (quarter of the year), monyy7. (Apr2004)...****;

data a;

input x : yymmdd10.;

cards;

2004-4-15

1960-1-2

2005-9-1

2007-2-14

2008?5?10

2001#1#1

;

run;

proc print data=a;

run;

data a_better;

format x yymmddn10.;

input x : yymmdd10.;

cards;

2004-4-15

1960/1/2

2005-9-1

2007-2-14

2008?5?10

2001#1#1

;

run;

proc print data=a_better;

run;

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2008-4-11 14:49:00

不用这么麻烦了

  date=compress(date,'-');
  date1=input(date,yymmdd10.);
  informat date1 yymmdd10.;
  format date1 yymmdd10.;
  drop date;
  rename date1=date;
  label date1='date';

  将这段程序插进去就可以了,格式和属性都可以得到更改。

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2008-4-12 13:19:00
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群