标题: 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
自知实在是懂的太少,都不好意思来发问题。谢谢各位高手帮忙。作者: 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;