SAS中文论坛

标题: One simple question about SAS code on Date format [打印本页]

作者: shiyiming    时间: 2009-8-8 22:00
标题: 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.
作者: shiyiming    时间: 2009-8-8 23:53
标题: 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]
作者: shiyiming    时间: 2009-8-12 11:04
标题: Re: One simple question about SAS code on Date format
to hopewell

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

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

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

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

自知实在是懂的太少,都不好意思来发问题。谢谢各位高手帮忙。
作者: shiyiming    时间: 2009-8-12 13:13
标题: Re: One simple question about SAS code on Date format
建议用SAS直接读取数据库
最好将日期数据读为numeric类型,如果先读为character再类型转换也行
设置时间条件可用where语句,where '01jan2009'd<date_variable<'31jan2009'd;




欢迎光临 SAS中文论坛 (https://mysas.net/forum/) Powered by Discuz! X3.2