由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - 工作中的SAS 编程请教
相关主题
请教个SAS问题工作中的SAS 编程请教
大家练练手吧,挺有意思的一道题这段SAS程序怎么理解?
[SAS] row merging帮忙看看这段SAS程序
问一个数据处理的问题,该如何实现单列转多行?14楼有图更新SAS help
Import excel file to SASask SAS code
SAS时间处理求教SAS code 问题
SAS 日期格式 YYMMDDn8.工作中SAS问题 —另一个问题请教!
Help on SAS: how to reconstruct recordssas question
相关话题的讨论汇总
话题: count话题: startdate话题: date2话题: enddate话题: data
进入Statistics版参与讨论
1 (共1页)
w********a
发帖数: 32
1

data A:
date y
2/1 0
2/2 1
2/3 1
2/4 0
2/5 0
2/6 1
2/7 0
2/8 1
2/9 1
2/10 1
;
自己琢磨了一阵子,不得窍门。需要知道y的value =1 每一次连续出现的次数 (最好
知道每次连续出现的起止日期)。由于实际数据很大, 不适合用Array.
final data will somehow look like:
date2 count
2/2 2
2/6 1
2/8 2
版上等, 谢谢大家!!
k*******a
发帖数: 772
2
my code, date1 is start time date2 is stop time(different from your
date2)
data A;
input date $ y;
datalines;
2/1 0
2/2 1
2/3 1
2/4 0
2/5 0
2/6 1
2/7 0
2/8 1
2/9 1
2/10 1
;
run;
data b;
set a;
lagy=lag(y);
if y^=lagy then group+1;
run;
data b(keep=date1 date2 count);
retain date1 date2;
set b;
by group;
if y=1;
if first.group then do;
count=0;
date1=date;
end;
count+1;
if last.group then do;
date2=date;
output;
end;
run;
proc print data=b;run;

【在 w********a 的大作中提到】
:
: data A:
: date y
: 2/1 0
: 2/2 1
: 2/3 1
: 2/4 0
: 2/5 0
: 2/6 1
: 2/7 0

r******m
发帖数: 369
3
data A;
input date $ y;
datalines;
2/1 0
2/2 1
2/3 1
2/4 0
2/5 0
2/6 1
2/7 0
2/8 1
2/9 1
2/10 1
;
/*create intermediate table that include rows you need*/
data middle (keep = startdate enddate count);
length startdate enddate $4;
retain startdate enddate count;
set a;
if y eq 0 then do;
count=0;
startdate=' ';
enddate=' ';
end;
if y eq 1 and count = 0 then do;
startdate = date;
enddate=date;
count + 1;
end;
else if y eq 1 and count >0 then do;
enddate = date;
count+1;
end;
run;
/*select rows you need*/
proc sql;
create table want as
select startdate,max(count)
from middle
where startdate is not null
group by startdate
order by startdate;
quit;
l*********s
发帖数: 5409
4
data B(drop=count);
set A;
retain count;
by y notsorted;
if first.y then count=1;
else count+1;
if last.y then c=count;
if c=. then delete;
run;
d******9
发帖数: 404
5
"by statement with unsorted option to identify the boundaries, and record
the starting date"
Great idea! Please give your full codes.

record

【在 l*********s 的大作中提到】
: data B(drop=count);
: set A;
: retain count;
: by y notsorted;
: if first.y then count=1;
: else count+1;
: if last.y then c=count;
: if c=. then delete;
: run;

k*******a
发帖数: 772
6
我也试过 by y,不过不行,原来要加 notsorted
学习了

【在 l*********s 的大作中提到】
: data B(drop=count);
: set A;
: retain count;
: by y notsorted;
: if first.y then count=1;
: else count+1;
: if last.y then c=count;
: if c=. then delete;
: run;

w********a
发帖数: 32
7
Appreciated all the help. :)
1 (共1页)
进入Statistics版参与讨论
相关主题
sas questionImport excel file to SAS
新手求教一个简单的SAS问题SAS时间处理求教
SAS 问题SAS 日期格式 YYMMDDn8.
求问SAS技术问题,one row to multiple rowHelp on SAS: how to reconstruct records
请教个SAS问题工作中的SAS 编程请教
大家练练手吧,挺有意思的一道题这段SAS程序怎么理解?
[SAS] row merging帮忙看看这段SAS程序
问一个数据处理的问题,该如何实现单列转多行?14楼有图更新SAS help
相关话题的讨论汇总
话题: count话题: startdate话题: date2话题: enddate话题: data