SAS中文论坛

 找回密码
 立即注册

扫一扫,访问微社区

查看: 804|回复: 3
打印 上一主题 下一主题

One simple question about SAS code on Date format

[复制链接]

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
楼主
 楼主| 发表于 2009-8-8 22:00:58 | 只看该作者

One simple question about SAS code on Date format

Hi,

I am a really beginner in SAS, here I got one question. I even don't know how to descripe my problem or name the question accurately. Sorry, I will try to make myself clear enough and look forward to getting your help, thanks!!!

I have one dateset, one variable is date. The format is Month/Day/Year/Time, for example, Jan120200:00:00, which means 2002, Jan 12, 00:00:00:. All the data is in this format, I want to extract all the data with the date of 2008, eg the year is "08". How could I write the code at this point?

Any explaination and help will be really helpful. Thanks.
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
沙发
 楼主| 发表于 2009-8-8 23:53:37 | 只看该作者

Re: One simple question about SAS code on Date format

不太明白
data set是SAS data set,还是外部数据?
如果是SAS data set,数据"Jan120200:00:00"是character还是picture后的datetime数据?
提取的数据"08"是想用于输出还是用于创建新变量?
如果是创建新变量,希望是2位的character,还是numeric?
[code:2fnjlsti]data temp;
        input temp $15.;
        year_1=put(substr(temp,6,2),$2.);
        date=input(cats(substr(temp,4,2),substr(temp,1,3),substr(temp,6,2),':',substr(temp,8)),datetime16.);
        year_2=substr(put(year(datepart(date)),4.),3);
        format date datetime16.;
datalines;
Jan120200:00:00
Feb120301:02:03
;[/code:2fnjlsti]
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
板凳
 楼主| 发表于 2009-8-12 11:04:03 | 只看该作者

Re: One simple question about SAS code on Date format

to hopewell

嗨!!!十分感谢你的解释。不过说实话,我也没太看懂你的话,太专业了,呵呵。

是这样,我有一组数据,应该叫TABLE吧,里面有N多个Variables. 其中一列是时间,比如临床患者去看医生的时间,格式是月/日/年。其实我也不太清楚具体的关于各个变量的Attribute,没专业的学过,只是略微带过一点,两年前,再就没用过。它肯定不是NUMBER吧,是不是什么CHARACTER 之类的,我也不清楚。真的不好意思问这么门外汉的问题。

现在是这样,所做的分析从统计学角度讲,简单的不能再简单了。所以我的问题应该不是专业的统计学方法问题。具体说我的问题是,我分析的一个条件是要限定时间,需要对从某年某月某日起到某年某月止的数据做一统计,可是在写CODE时,我不知道用什么CODE能把这个时间限制出来。不是NUMBER的格式,肯定不能用大小值限定了,所以该用什么样的CODE呢?

另,我的数据16万条。想通过EXCEL导都导不了,太大。无论什么办法,能提高效率,都十分十分感谢。

自知实在是懂的太少,都不好意思来发问题。谢谢各位高手帮忙。
回复 支持 反对

使用道具 举报

49

主题

76

帖子

1462

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
1462
地板
 楼主| 发表于 2009-8-12 13:13:01 | 只看该作者

Re: One simple question about SAS code on Date format

建议用SAS直接读取数据库
最好将日期数据读为numeric类型,如果先读为character再类型转换也行
设置时间条件可用where语句,where '01jan2009'd<date_variable<'31jan2009'd;
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SAS中文论坛  

GMT+8, 2026-2-5 21:36 , Processed in 0.069067 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表