由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - questions about a SAS code
相关主题
求教 SAS数据转化ASK FOR ONE SAS QUESTION
如何将SAS DATA中的变量名改名(不知道原变量名的前提下)填充缺失值 问题请教 (SAS, R, 所用软件不限)
问一个关于SAS的循环的问题[SAS] multi-thread programming and parameters...
请教sas高人(数据读入)sas question
一个sas问题请教SAS编程
question about longitudinal data求助:data manipulation的一个问题
一个SAS问题,合并行SAS help
sas question一个简单的SAS 问题
相关话题的讨论汇总
话题: appearance话题: sas话题: counter话题: once话题: times
进入Statistics版参与讨论
1 (共1页)
d**********2
发帖数: 14
1
Hi,
I have a data which contains only one variable, the value of which is either
1 or 2, so that the data looks like this, 1221111222221221222 (of course
this is what it looks like after I transposed it). Now I need to know how I
could calculate the number of times 1 and 2 appeared CONSECUTIVELY, for
example, in this case, 1 made a single appearance for 3 times and made a
quadraple appearance for once, 2 made a double appearance for twice, a
triple appearance for once and a 5-times-in-a-row appearance for once. How
do I write a sas code to achieve this?
Thanks you so much!
Laomao
R*********i
发帖数: 7643
2
Using the data in original stacking structure, assume variable name is var
and dataset name is test:
data test1;
set test;
by var notsorted;
retain counter;
if first.var then counter=1;
else counter=counter+1;
if last.var then output;
run;
proc sql;
select var,counter,n(counter) as numtimes
from test1
group by var,counter
order by var,counter;
quit;
1 (共1页)
进入Statistics版参与讨论
相关主题
一个简单的SAS 问题一个sas问题
请教一个SAS问题question about longitudinal data
请教:get next record using BY group (SAS code data manipulation)一个SAS问题,合并行
急!一个简单的SAS问题,请大家帮帮解释一下!多谢!sas question
求教 SAS数据转化ASK FOR ONE SAS QUESTION
如何将SAS DATA中的变量名改名(不知道原变量名的前提下)填充缺失值 问题请教 (SAS, R, 所用软件不限)
问一个关于SAS的循环的问题[SAS] multi-thread programming and parameters...
请教sas高人(数据读入)sas question
相关话题的讨论汇总
话题: appearance话题: sas话题: counter话题: once话题: times