全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
10633 7
2008-10-24
我从CSMAR数据库下载了日期数据,但是导入到SAS后,全是字符型的,我想将该变量转换为日期型,请问应该如何做?谢谢
二维码

扫码加我 拉你入群

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

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

全部回复
2008-10-24 21:57:00

how does your data look like? suppose it is ddmmyy10.

new_var = input(old_var, ddmmyy10.);

二维码

扫码加我 拉你入群

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

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

2008-10-25 00:44:00

I don't think it works using the SAS code above. Please see the following SAS code.

The hospitalization date is characteristic variable in the data set a as HOSPADMIT, such as '19991103'.

It means in the year '1999', 'NOV.', and date  '03' The hospitalization date should be transferred to '03NOV1999'

in the data set b as variable of HOSP_ADMIT_DT.

Please try it.

Data b;

Set a;

HOSP_ADMIT_YYYY = substr(HOSPADMIT, 1,4);

HOSP_ADMIT_MM = substr(HOSPADMIT, 5,2);

HOSP_ADMIT_DD = substr(HOSPADMIT, 7,2);

HOSP_ADMIT_DT = MDY(HOSP_ADMIT_MM, HOSP_ADMIT_DD, HOSP_ADMIT_YYYY);

format HOSP_ADMIT_DT date9.;

DROP HOSPADMIT HOSP_ADMIT_YYYY HOSP_ADMIT_MM HOSP_ADMIT_DD;

Run;

 

[此贴子已经被作者于2008-10-25 1:05:20编辑过]

二维码

扫码加我 拉你入群

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

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

2008-10-25 02:09:00

in that case then

new_var = input(old_var, yymmdd8.);

I made an assumption at the first place. Yes, you are right, It will depend on how the format the old variable looks like.

In your code, the YYYY, MM and DD variables are still character variables. you have to use input function to transpose.

[此贴子已经被作者于2008-10-25 2:14:00编辑过]

二维码

扫码加我 拉你入群

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

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

2008-10-25 06:42:00

Thank you for your reply. In that case, your code is right.

Your code uses the function of "INPUT". My code uses the function of "MDY". My understanding, in some cases, the INPUT function is easy to manipulate, to transfer one characteristic variable to numeric or date variable using argument option.

In some cases, if the date, month, and year are separated to different characteristic variables, the MDY function could combined them together and transfer it to date variable.

[此贴子已经被作者于2008-10-25 6:44:05编辑过]

二维码

扫码加我 拉你入群

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

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

2008-10-25 13:12:00
感谢楼上二位
二维码

扫码加我 拉你入群

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

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

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

说点什么

分享

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