全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
3490 8
2009-11-10
I have the dataset with a column of DATE. However, my supervisor arranged the file from different sources. So the column of DATE in the excel file are not all in DATE formate. eg.

There are both 25/06/2001, and 20000312 in that column, which the first is DATE format, but the second is recognized as numerical value. It's fairly easy to input just with either of them. But how to input both types of DATE presenting in the same column?

Thank you very much.

And i want convert both to the format of yymmddn8., ie(20000312, this is data format in SAS, but not in EXCEL of my original data file.).
二维码

扫码加我 拉你入群

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

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

全部回复
2009-11-10 09:28:35
if a is date, do nothing
if a is numeric, transform
simple if then statement
二维码

扫码加我 拉你入群

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

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

2009-11-10 09:35:21
yes offcoz... I wanna know what code i can use to determine if it is in a date format or it's a numerical value.

because SAS only have formats of Char and numerical, and DATE is a numerical value as well.
二维码

扫码加我 拉你入群

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

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

2009-11-10 09:35:37
yes offcoz... I wanna know what code i can use to determine if it is in a date format or it's a numerical value.

because SAS only have formats of Char and numerical, and DATE is a numerical value as well.
二维码

扫码加我 拉你入群

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

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

2009-11-10 12:42:53
try this one:

data test;
input a $20.;
if length (trim(a)) = 10 then do;
   year = substr(trim(a),7,4);
   month= substr(trim(a),4,2);
   day  = substr(trim(a),1,2);
   b = mdy(month,day,year);
   end;
if length(trim(a)) = 8 then do;
   year = substr(trim(a),1,4);
   month= substr(trim(a),5,2);
   day  = substr(trim(a),7,2);
   b=mdy(month,day,year);
   end;
cards;
25/05/2001
20000312
19990909
12/01/2009
;
run;
proc print data = test;
var b;
format b yymmdd8.;
run;

output:
Obs           b

                                          1     01-05-25
                                          2     00-03-12
                                          3     99-09-09
                                          4     09-01-12
二维码

扫码加我 拉你入群

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

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

2009-11-10 21:54:14
4# windlove
复制代码
问题哪有你描述的那么复杂?
because SAS only have formats of Char and numerical...,
SAS仅仅有关date的formats 就有几十个。
二维码

扫码加我 拉你入群

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

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

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

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