由买买提看人间百态

topics

全部话题 - 话题: datalines
首页 上页 1 2 3 4 5 6 7 (共7页)
t******o
发帖数: 70
1
data test;
input id $ yr asset netp;
datalines;
111 2012 23 11
111 2010 25 10
111 2009 39 20
111 2011 29 12
123 2008 9 4
123 2009 8 3
123 2010 7 2
;
run;
想要的结果是这样的:
id yr asset netp asset_py netp_py
111 2012 23 11 25 10
111 2011 25 10 39 20
111 2010 39 20 . .
111 2008 29 12 . .
123 2010 9 4 8 3
123 2009 8 3 7 2
123 2008 7 2 . .
解释:新产生的两列是对应previous year的值。
请教应该怎么实现,非常感谢!
k*******a
发帖数: 772
2
来自主题: Statistics版 - 问个sql问题
try this, not sure about its efficiency
data test;
input id item $;
datalines;
1 A
1 C
1 K
2 B
2 C
2 U
2 Z
3 A
;
run;
proc sql;
select distinct id
from test
group by id
having sum(item="B") and sum(item="C");
quit;
k*******a
发帖数: 772
3
data a;
input ID V2 V3;
datalines;
1 -1 0
1 0 2
1 3 1
1 10 1
1 4 3
2 0 4
2 -1 3
2 2 5
2 2 1
3 1 1
3 1 1
3 1 1
3 2 1
;
run;
proc sql;
create table b as
select *
from a
where id not in (select distinct id from a where V2 < 0 or V2 >5);
quit;
z**o
发帖数: 149
4
来自主题: Statistics版 - 求助:一个SAS小程序
一列数据,想知道每个number在整体的percentile,没找到sas里直接能做的procedure
,用macro的话:
data a1; input x;
datalines;
2
6
3
2
2
1
3
8
6
10
5
9
1
6
2
5
10
;
proc univariate data=a1 noprint;
var x;
output out=a2 pctlpre=p_ pctlpts= 1 to 100 by 1;
run;

proc sql;
create table a3 as
select *
from a1, a2 ... 阅读全帖
C******t
发帖数: 72
5
来自主题: Statistics版 - 跪问一个data management的问题
大概可以这样:
data Test;
input id ATime BTime;
dataline;
.....;
proc sql;
create table Intermediate as
select a.id, a.Btime, b.Atime, a.Btime-b.Atime as TimeDiff
from Test a
left outer join Test b
on a.id=b.id and a.Btime>=b.Atime
order by a.id, a.Btime, calculated TimeDiff;
quit;
data Final;
set Intermediate;
by id Btime TimeDiff;
if first.Btime then output;
run;
j******o
发帖数: 127
6
来自主题: Statistics版 - 怎么用SAS transpose这两dataset呀?
data have;
input index var1 $ var1_description $ var2 $ var2_description $;
datalines;
1 cd02 cd02_text cd05 cd05_text
2 cd05 cd05_text cd03 cd03_text
3 cd03 cd03_text cd04 cd04_text
4 cd10 cd10_text cd08 cd08_text
;
run;
data obtain;
set have(keep=index var1 var1_description rename=(var1=var var1_
description=description))
have(keep=index var2 var2_description rename=(var2=var var2_
description=description));
by inde... 阅读全帖
k*******a
发帖数: 772
7
来自主题: Statistics版 - 求大牛解答 SQL 问题
you can create a score for each obs, then find the maximum score, for
example
data test;
input id var1 $ var2 $ var3$;
datalines;
1 A B B
1 B C B
1 A B C
2 A A B
2 A A B
2 C C B
3 C A A
3 B A A
3 A A A
;
proc sql;
select *, 100*((var3='C')*3 + (var3='B')*2 + (var3 = 'A'))
+ 10*((var2='C')*3 + (var2='B')*2 + (var2 = 'A'))
+ ((var1='C')*3 + (var1='B')*2 + (var... 阅读全帖
k*******a
发帖数: 772
8
来自主题: Statistics版 - 求大牛解答 SQL 问题
then you can use format to order the way you want
data test;
input id var1 $ var2 $ var3$;
datalines;
1 A B B
1 B C B
1 A B C
2 A A B
2 A A B
2 C C B
3 C A A
3 B A A
3 A A A
;
run;
proc format;
value $fmtest 'C' = 1
'B' = 2
'A' = 3;
run;
data test1;
set test;
var1f = put(var1, $fmtest.);
var2f = put(var2, $fmtest.);
var3f = put(var3, $fmtest.... 阅读全帖
n*****5
发帖数: 61
9
来自主题: Statistics版 - sas 题目问问
Consider the following dataset:
data StudentScore;
length studentID $ 1. year 3. score 3.;
input studentID year score;
datalines;
A 91 400
A 92 398
A 92 399
B 91 430
B 92 432
B 93 444
B 94 446
C 91 455
C 92 423
C 93 411
C 94 415
C 95 427
C 95 418
run;
Q1. Create a variable called “Flag” which indicates whether a student’s
score increased or decreased from the previous record in the data. Mark a “
0” for records where the student’s s... 阅读全帖
k*******a
发帖数: 772
10
来自主题: Statistics版 - 请教:SAS处理Longitudinal data 的问题
for each subject at each time, find total units given within 24 hours after
this time. Then find any subject having any total units exceeding 5. I have
an example, the time is a little different, I use 1 as threshold
You need to make sure sum over units for each id at each unique time, that
is, no duplicate for id/time key
data test;
input subject time units;
datalines;
1 0 1
1 0.1 2
1 0.9 3
1 1.6 1
2 0 1
2 0.1 1
2 1.1 2
2 1.9 2
;
proc sql;
select distinct a.subject
from test a, test b
whe... 阅读全帖
j******o
发帖数: 127
11
来自主题: Statistics版 - 请教:SAS处理Longitudinal data 的问题
如果你的data不是特别大并且想使用data step:
data have;
input subject time : datetime. units;
format time datetime.;
datalines;
1 19JUN13:13:09:00 1
1 20JUN13:10:09:00 1
1 22JUN13:02:12:00 2
1 22JUN13:08:12:00 4
1 24JUN13:08:12:00 3
2 17JUN13:12:33:00 1
2 21JUN13:15:03:00 1
;
run;
data obtain;
set have nobs=nobs;
by subject;
retain Max_TU24;
if first.subject then Max_TU24=0;
TU24=... 阅读全帖
l**********8
发帖数: 305
12
来自主题: Statistics版 - 问道作业题
作业不会写,请各位帮忙
2) Below are hypothetical data containing contact information for
sending a survey to patients. These data are made up and any resemblance to
real people with similar names or addresses is purely coincidental. Insert
the lines below into your SAS program. Do not make any alterations to the
data! Copy them exactly as shown below.
datalines;
Sonya Larson
10054 Plum Tree Rd
Buffalo NY 10068
716-555-1348
Peter Simpson
605 Glendover Dr
Isa... 阅读全帖
k*******a
发帖数: 772
13
来自主题: Statistics版 - 求助:一个SAS的小问题
there are many ways to do this, here is my solution:
data MyData;
input firm $ x;
datalines;
F1 1
F2 3
F3 5
F3 6
F1 9
F2 99
F6 3
;
run;
proc sql noprint;
select distinct firm into :data separated by ' ' from MyData;
select distinct "if firm ='"||strip(firm)||"' then output "|| firm into
:code separated by '; ' from MyData;
quit;
data &data;
set MyData;
&code;
run;
l*******s
发帖数: 197
14
来自主题: Statistics版 - 请教个SAS数据输入问题
数据格式如下.
共五列,前面四个是数子,分别属于不同的分类,后面一列所属门类
375 447 547 548 a
286 286 403 422 b
349 382 473 497 c
429 410 488 547 a
我想做成Stack数据,想一次输入,结果很难实现。请教高手如何写代码?
下面的代码只能把数字录入,后面的字母则不行;
data test;
do type ='x', 'y', 'z','m','n';
input value @@;
output;
end;
input cat $;
datalines;
t*****w
发帖数: 254
15
来自主题: Statistics版 - [Help] SAS CODE FOR RANDOM SAMPLING
Data controls;
Input site$ year$ id;
Datalines;
A01 1996 1
A01 1996 2
A01 1996 3
A01 1996 4
A01 1999 5
A02 1996 6
A02 1996 7
A02 1996 8
A02 1996 9
A02 1996 10
A02 1996 11
A02 1996 12
A02 1997 13
A02 1997 14
A02 1997 15
A02 1997 16
A02 1997 17
A02 2000 18
;
data ratio;
set controls;
x = RAND('BERNOULLI',0.2) ;
if x eq 1 then output;
;
run;
k*****u
发帖数: 45
16
来自主题: Statistics版 - help on a sas question
刚学macro和sql不久,想了个笨办法,lz找到了更好的办法的话不要笑我。。。
data a;
input v1 v2 v3 f1;
datalines;
4 5 6 1
2 3 9 3
2 5 7 2
;
run;
%macro test;
proc sql;
alter table a
add v num
;
%do i=1 %to 3;
update a
set v=v&i
where a.f1=&i
;
%end;
quit;
%mend;
%test;
w****r
发帖数: 28
17
来自主题: Statistics版 - help on a sas question
data a;
input v1 v2 v3 f1;
datalines;
4 5 6 1
2 3 9 3
2 5 7 2
run;
data b;
set a;
array v[1:3] v1-v3;
newvalue = v[f1];
run;
a*******y
发帖数: 105
18
来自主题: Statistics版 - 操作pair data加flag
下面这个估计可以, 你自己再改改好了
data d;
input c1 $ c2 $;
datalines;
a b
b a
c d
d c
q r
r q
s t
s t
;
run;
proc sql;
select m.c1, m.c2,
case
when m.c1 < m.c2 then 'Y'
else 'N'
end as flag
from d as m, d as n
where m.c1 = n.c2 and m.c2 = n.c1;
quit;
j******o
发帖数: 127
19
Not fancy, but should works.
------------------------------------
data have;
input time $;
datalines;
10175996
10175925
;
run;
data obtain;
set have;
if input(substr(time, 7,2), best12.)<=30 then time1=substr(time, 1, 6);
else do ;
x=input(substr(time, 1,6), best12.)+1;
time1=put(x,z6.);
end;
run;
------------------------------------
S******y
发帖数: 1123
20
来自主题: Statistics版 - SAS variable +(-1) 是什么意思?
see PUT statement and list output in SAS Online Doc
----------------------------------
/* A more meaningful example */
data _null_;
input idno name $ startwght;
put name 'weighs ' startwght +(-1) '.';
datalines;
032 David 180
049 Amelia 145
219 Alan 210
;
These lines are written to the SAS log:
David weighs 180.
Amelia weighs 145.
Alan weighs 210.
-----------------------------------
The +(-1) pointer control moves the pointer backward to remove the unwanted
blank that occurs between the... 阅读全帖
d********i
发帖数: 193
21
try this:
data da;
input id year;
datalines;
1 1
2 4
3 2
4 7
5 9
6 6
7 10
;
run;
data da2;
set da;
array n{10} n1 - n10;
do i = 1 to 10;
if i <= year then n{i} = 0; else n{i} = .;
end;
drop i;
run;
z********8
发帖数: 172
22
来自主题: Statistics版 - April 22/ 2014 SAS BASE PASS
我今天过了SAS BASE, 没有SAS经验,我是从版上拿的资料,所以想回馈。。。。
不过我现在觉得应该很少有人过不了base的
Anyway
贴上来希望对后来的同学有利,也为自己攒点人品
很多70题上面的,我能记住的都写出来, 64题,全部选择题,也没有填空
1(选项变了), 3, 4, 5, 7, 10, 11, 12 (JAN, FEB, MAR变成其他的,题目意思没变)
, 14, 15, 17, 18(变了), 19, 20 , 21,
23(sasdatafolder), 24, 25, 26, 27, 28, 30, 31, 33, 34, 35, 36, 40, 42, 45
, 46, 47, 49, 50, 51, 52, 53, 54, 56, 59, 60, 61 (变形),
63, 65, 67, 69, 70(问法变)
explanation:
1 ) 两个地方 insert code, 选项变了,变成分开问, 答案还是Gender
12) JAN, FEB, MAR 变成 item1, item2, item3, 选项也随之变了,但是意思不变... 阅读全帖
v***v
发帖数: 267
23
来自主题: Statistics版 - 问个sql的问题吧,搞不出来了.
data a;
input
row1
v1
v2
@13 v3 yymmdd10.
;
format v3 yymmdd10.;
datalines;
0 1 89 2011-07-05
0 1 91 2013-07-20
1 1 91 2013-07-25
0 2 81 2010-10-18
1 2 82 2011-03-22
1 3 89 2011-01-04
0 3 91 2012-06-27
0 3 91 2012-10-16
0 3 91 2012-10-20
0 4 84 2012-03-31
1 4 84 2012-04-17
1 5 73 2011-07-20
2 5 75 2012-12-27
0 5 75 2013-03-19
0 5 76 2013-10-09
3 5 76 201... 阅读全帖
k*****8
发帖数: 91
24
想把两个数据放入同一个Excel的不同工作簿里面。用了两种方法但是都是第二个
dataset把之前的一个dataset覆盖了(i.e.output里面只有demog这个dataset)。请问
这是什么原因?还有什么其他的方法能够实现在一个Excel里面建立多个工作簿?
data test demog;
input id $ sex $ age;
if sex='f' then output test;
else output demog;
datalines;
001 f 9
394 m 10
204 f 20
395 f 3
;
run;
/*Method 1*/
ods listing close;
ods tagsets.excelxp file="c:\temp\test4.xml" style=minimal;
ods tagsets.excelxp options(Sheet_Name='Class Data');
proc print data=test;
run;
ods tagsets.excelxp options(Sheet_Name='Demog Data');... 阅读全帖
k*****8
发帖数: 91
25
请问大家知道有什么方法可以将SAS做出来的图存入Excel文件(.xls, .xlsx, .xlsb,
etc.)里面?
比如有如下的dataset
data test;
input seq grade1 grade2;
datalines;
1 85 90
2 88 87
3 79 82
4 90 85
;
然后做一个简单的折线图,存入Excel文档中。
提前谢过了。
s*********e
发帖数: 1051
26
来自主题: Statistics版 - Please help with a SAS macro
data one (drop = var2);
input Month Var1 Var2;
datalines;
201401 2 2.00
201402 4 3.00
201403 5 3.67
201404 8 4.75
201405 10 5.80
201406 12 6.83
201407 21 8.86
;
run;
proc sql;
create table two as
select b_month, mean(a_var1) as var2
from
(select
a.month as a_month,
b.month as b_month,
a.var1 as a_var1
from one as a, one as b where a.month <= b.month)
group by b_month;
quit;
proc print data =two;
run;
s*********e
发帖数: 1051
27
来自主题: Statistics版 - sas programming question
这行吗?
data one;
input Name $ Score;
if score < 10 then score = .;
datalines;
A 766
A 9
A 93
A 869
A 143
B 8
B 119
B 362
B 6
B 95
C 524
C 99
C 123
C 176
C 210
;
run;
proc sort data = one;
by name score;
run;
data two;
set one;
by name score;
if first.name then n = 1; else n + 1;
if n = 2 and lag(score) = . then score = .;
run;
proc print data = _last_; run;
D******n
发帖数: 2836
28
来自主题: Statistics版 - Another SAS question
data a1;
input x $ y $ z;
datalines;
a A 1
a A 2
a C 3
b C 1
b B 2
b B 3
b A 4
b D 5
c A 1
c C 2
d D 1
d A 2
e A 1
e D 2
;
run;
proc print;run;
data a2;
set a1;
by x;
if first.x then cum_A = 0;
cum_a + (y="A");
num = _n_;
run;
proc sql;
select * from a2
group by x
having cum_a>=max(cum_a) and sum(cum_a)>1
order by x,num;
quit;
q******n
发帖数: 272
29
来自主题: Statistics版 - SAS code error?
为什么这段code没有写入数据? 我晕头了? 谢谢
data test;
input id 1-3 sex $ 4 height 5-6 weight 7-11;
datalines;
001M68155.5
001M68155.5
;

run;
v*********w
发帖数: 1632
30
来自主题: Statistics版 - data distribution fit
I have run a data distribution fit code below.
Can anybody help me figure out why the histogram cannot be output?
Thanks.
data Plates;
label Gap = 'Plate Gap in cm';
input Gap @@;
datalines;
0.746 0.357 0.376 0.327 0.485 1.741 0.241 0.777 0.768 0.409
0.252 0.512 0.534 1.656 0.742 0.378 0.714 1.121 0.597 0.231
0.541 0.805 0.682 0.418 0.506 0.501 0.247 0.922 0.880 0.344
0.519 1.302 0.275 0.601 0.388 0.450 0.845 0.319 0.486 0.529
1.547 0.690 0.676 0.314 ... 阅读全帖
m***d
发帖数: 192
31
The following program is submitted.
data WORK.TEST;
input Name $ Age;
datalines;
John +35
;
run;
Which values are stored in the output data set?
Z********6
发帖数: 10
32
来自主题: Statistics版 - 新手问个简单的sas问题
data test;
input day $ x @@;
datalines;
1 0 1 0 1 0
2 0 2 1 2 1 2 0 2 0
3 1 3 0
;
run;
data test1(drop=x);
set test;
by day;
if first.day then y=0;
if x=1 and y=0 then y+1;
else if y>0 then y+1;
if last.day;
run;
f****s
发帖数: 7
33
来自主题: Statistics版 - 弱问一个SAS 里data managerment的问题
data test;
input ID VALUE_DATE VALUE;
datalines;
1 1999 0
1 2000 0
1 2001 10
1 2002 20
1 2003 30
2 1999 5
2 2000 0
2 2001 5
2 2002 10
3 1999 0
3 2000 5
3 2001 0
3 2002 10
3 2003 20
;
run;
proc sort data=test ;by id VALUE_DATE ;
run;
*Get the cutoff date;
data cutoff;
set test;
by id VALUE_DATE;
if value=0 then cutoffdt=VALUE_DATE;
retain cutoffdt;
if last.id;
keep id cutoffdt;
run;
data final;
merge test cutoff;
... 阅读全帖
e*******0
发帖数: 335
34
刚考完sas base, 我感觉如果单纯刷50+70+123题可能会在及格线边缘徘徊,原题并没
有那么多。但难度比较大的都是原题,不是原题的都是细节题,看过就知道,没看过就
答不上来。
补充两个我大意了的考点
1. split options. 同label 连用,可以将wrap label. 考题大概是
label = "A**B", 选择 split = '*'可去除label 里面的"*".
2. 有一题考do loop,然后一个do until 和 一个do year = 2012 to 2021选项,我
压根没看出来两个有什么不同,随便猜了一个,说明do loop怎么运行是一个考点。
3. 提供error information,判断哪里出错了。有一个是考datalines的正确写法,这
个我貌似没见过
就只记得这些啦,另外问问sas专家,我准备把sas base和advance那两本书都卖了,入
一本little sas当作reference可以吗?因为感觉前面两个太应试了,而且知识点找起
来并没有很方便。请问little sas好吗?cover advance 的东西... 阅读全帖
t*********g
发帖数: 136
35
数据量这么小的话,干嘛不手动修改一下格式再让sas读?
或者你一定要用程序读的话,我觉得比较简单的是下面这种方法。
不过你要知道每组的个数。
data test;
input values @@;
if 1 <= _N_ <= 10 then sex = 'M';
.........;
datalines;
78 70 79 78 77 78 69 72 73 75
.........
;
run;
s******8
发帖数: 102
36
or this is what you want.
Data airline;
length carrier car1-car4 $20.;
Infile datalines DLM='' missover ;
array car(4) $ ("delta airlines","southwest airlines","american airlines","
united airlines");
if mod(_n_,2) eq 0 then sex='female';
else sex='male';
do subj=1 to 15;
input rating @;
carrier=car(mod(subj-1,4)+1);
if not missing(rating) then output;
end;
drop subj car1-car4;
run;
f**z
发帖数: 154
37
来自主题: Statistics版 - 请教一个SAS数据格式的问题
问题是这样的。比如有这么一个程序。
data abc;
informat x 6.2;
x=12345;
input y 6.2;
put x= y=;
datalines;
12345
;
run;
于是log里会得到x=12345 y=123.45. 我想知道第二行的informat里写什么格式可以让x
也被读成123.45呢?
谢谢!
e*******c
发帖数: 1479
38
来自主题: Statistics版 - 请教一个SAS数据格式的问题
不知道如何直接改informat 可以变x , 但可以直接使用简单的
data abc;
input x 6.2 y 6.2;
put x= y=;
datalines;
12345 12345
;
run;
B******y
发帖数: 9065
39
来自主题: Statistics版 - Re: 如何快速的将单行分成多行
多谢你的热心帮忙!不过我不是太明白你的意思。假设我的原始数据已经如下输入好了:
data my_data;
input id $ index $200.;
datalines;
A 11
B 1 & 8
C 2, 3, 10
D 5 7
E 7 and 8
;;;;
那么怎么就my_date分解行呢?像你这样重输是没有意义的,因为index可能含的数值很
多,有超过10个以上的可能,所以重要的第一步是先读出数值的个数,然后再分解用
transpose转行。我的最初思路就是如此,但不够快速简洁,希望能有更好的办法。
w*******y
发帖数: 60932
40
CyberPower
1500VA/900Watts
Un-interruptible Power Supply
8 Outlet
LCD Diagnostic Display
ADDED VALUE: TRVL918 Travel Surge
The Intelligent LCD Series CP1500AVRLCD UPS, designed for mid to high-end
computer systems, features dynamic line conditioning and a LCD diagnostic
display.
Real-time system vitals can be viewed from this Crystal-Blue (see below)
display. The unit can be conveniently mounted in a workstation cabinet, or
directly on the desktop. The CP1500AVRLCD guards against surges/spikes, ... 阅读全帖
w*******y
发帖数: 60932
41
Vanns.com has the APC-J10 600W UPS Power Conditioner for sale for $129.88
Free shipping.
This is for a home theater system.
Silver.
Link:
http://www.vanns.com/shop/servlet/item/features/753029720/apc-j
Its part of their deal-of-the-day
Link:
http://www.vanns.com/shop/servlet/dealoftheday?i_c=dealoftheday
Additional Details:
Comparison Specifications
Output Power Capacity: 600W / 1000VA
Max Configurable Power: 600W / 100VA
Waveform Type: Stepped Approximation To A Sinewave
Output ... 阅读全帖
首页 上页 1 2 3 4 5 6 7 (共7页)