y****n 发帖数: 46 | 1 data a;
input A 4. B 4. C 4. D 4. ;
datalines;
1
7
3 3
2 5
5
5 3
4 5
5 8
2 3
1
;
run;
proc transpose data=a out=b prefix=n;
var a b c d;
run;
data c;
array xx{10} n1-n10;
set b;
rec=0;
do i=1 to 10;
if xx(i)>=0 then do;
new=xx(i);
rec+1;
output;
end;
end;
keep rec _name_ new;
run;
proc sort data=c;
by rec _name_;
run;
proc transpose data=c out=d(drop=_name_ rec);
by rec;
... 阅读全帖 |
|
a*****3 发帖数: 601 | 2 data mqrlkr;
input mqrlkr :$100.;
mqrN = put(input(mqrlkr, mmddyy.), date9.); datalines;
5/6/60
;
赏个包子怎么样? 我这儿天寒地冻, 住着半个密林的房子 房东还不给开暖气 还让不
让人活了?
2010: ") since it is substred from other original database. I checked and
found : that its length is $92. Probably that's the reason why input(Date,
mmddyy10: .) doesn't work here. |
|
k*******a 发帖数: 772 | 3 我的笨方法,不过可以用
data a;
input SCHOOLID;
datalines;
1
1
5
6
10
10
10
11
;run;
proc sql;
select count(distinct schoolid) into :n
from a;
%let n=%trim(&n);
proc sql;
select unique schoolid into :name1-:name&n
from a;
quit;
%macro dummy;
data dummy;
set a;
%do i=1 % to &n;
if &&name&i=schoolid then school_&&name&i=1;
else school_&&name&i=0;
%end;
run;
%mend;
%dummy
proc print data=dummy;run; |
|
k*******a 发帖数: 772 | 4 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 pr... 阅读全帖 |
|
r******m 发帖数: 369 | 5 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 ... 阅读全帖 |
|
w********a 发帖数: 32 | 6 有一个新的问题。
Original data.
data A;
input date $ y;
datalines;
2/1 0
2/2 -1
2/3 0
2/4 0
2/5 0
2/6 1
2/7 0
2/8 -1
2/9 0
2/10 1
;
run;
y的value为-1 是一个事件的开始,y的value为1是一个事件的结束日期。要想把事件中
所有的-1和0变成1.
final data:
2/1 0
2/2 1
2/3 1
2/4 1
2/5 1
2/6 1
2/7 0
2/8 1
2/9 1
2/10 1
大家有没有好的办法呢?
谢谢了!! |
|
s******r 发帖数: 1524 | 7 data testt;
input id $3. cat val ;
datalines;
aaa 1 123
aaa 2 456
aaa 9 789
bbb 1 235
bbb 9 666
ccc 1 124
ccc 2 675
ccc 3 222
ccc 9 111
;
run;
proc sort data=testt;by id;run;
data testt_new;merge testt testt(where=(cat9=9) rename=(val=val9 cat=cat9));
by id;
drop cat9;
run;
ID |
|
o**********a 发帖数: 330 | 8 data four;
input a $;
datalines;
2
2.3
2.34
;
run;
data five;
set four;
a_num=input(a,4.2);
run;
proc print data=five;
run;
输出:
Obs a a_num
1 2 0.02
2 2.3 2.30
3 2.34 2.34
第一个记录变成0.02了,
应该怎么解决啊,多谢了
我是个sas菜鸟 |
|
l*****8 发帖数: 483 | 9 data four;
input a $;
datalines;
2
2.3
2.34
;
run;
data five;
set four;
a_num=a*1;
run; |
|
P****D 发帖数: 11146 | 10 data four;
input a $;
datalines;
2
2.3
2.34
;
run;
data five;
set four;
a_num=input(a,best.);
format a_num 4.2;
run;
proc print data=five;
run; |
|
D**g 发帖数: 739 | 11 陈老师是会SAS的吧?PROC MCMC里有个例子,你何不用你的理论,给大家演示一下具体
算法,最后看看你的算法和结果和贝叶斯结果,frequentist算法有何区别。
Example 52.6 Change Point Models
Consider the data set from Bacon and Watts (1971), where is the logarithm of
the height of the stagnant surface layer and the covariate is the logarithm
of the flow rate of water. The following statements create the data set:
title 'Change Point Model';
data stagnant;
input y x @@;
ind = _n_;
datalines;
1.12 -1.39 1.12 -1.39 0.99 -1.08 1.03 -... 阅读全帖 |
|
k*******a 发帖数: 772 | 12 你可以先按照b 把a的值group起来,然后在求和
data a;
input A B;
datalines;
1 2
4 1
2 3
1 2
3 1
1 2
;
proc print;run;
data b(keep=group);
set a;
group+1;
do i=1 to B;
output;
end;
proc print data=b;run;
data c;
merge a b;
if A ne .;
run;
proc sql;
select sum(A)
from c
group by group;
quit; |
|
s******y 发帖数: 352 | 13 data a;
input A B;
datalines;
1 2
4 1
2 3
1 2
3 1
1 2
;
run;
data b;
set a;
call missing(c);
do _n_=1 to B;
set a (keep=a);
c+a;
end;
run;
BAOZI please!! |
|
k*******a 发帖数: 772 | 14 a2=a1-lag(a1);
if _n_=1 then a2=a1;
或者
data a;
retain a1 0;
a2=a1;
input a1;
a2=a1-a2;
datalines;
10
20
40
20
; |
|
a********a 发帖数: 346 | 15 It is easy.
data one;
input ID DATE$ FACILITY_TYPE;
dat=input(date, MMDDYY10.);
format dat MMDDYY10.;
datalines;
1 1/1/2010 0
1 1/2/2010 0
1 1/3/2010 0
1 1/4/2010 1
1 1/5/2010 1
1 1/6/2010 0
1 1/7/2010 0
2 1/1/2010 0
2 1/2/2010 0
2 1/3/2010 1
2 1/4/2010 1
2 1/5/2010 0
2 1/6/2010 1
2 1/7/2010 1
2 1/8/2010 0
2 1/9/2010 0
;
run;
proc sort data=one;
by id dat FACILITY_TYPE;
run;
data t... 阅读全帖 |
|
s*********r 发帖数: 909 | 16 infile datalines dlm='" "'; |
|
d******9 发帖数: 404 | 17 input id height weight;
These variables are defined as NUMERIC !
However,
datalines;
"1" "68" "144"
"2" "78" "202"
;
They are character values when you use " ", and "" is part of data value.
When you remove "", they are read in as numeric values. |
|
s******r 发帖数: 1524 | 18 you need define
'根本不是日期的值'
data test;
length xx $15.;
input xx $15.;
if index(xx,'')>1 then yy=input(xx,mmddyy10.);
else yy=.;
datalines;
3\3\1996
10\4\2006
10\20\2006
4\15\1997
13\15\1996
11\35\1988
11789
;
run; |
|
l***o 发帖数: 5337 | 19 data old;
input start end;
datalines;
1 1
1 2
1 3
1 4
1 5
1 6
1 7
2 1
2 2
3 1
3 2
3 3
3 4
3 5
;
run;
data temp_1;
set old;
end_lag = lag1(end);
if start = lag1(start) then timediff = end - lag1(end);
run;
proc print;
run;
data temp_2;
set old;
end_lag = lag1(end);
if start = lag1(start) then timediff = end - end_lag;
run;
proc print;
run;
结果temp_1和temp_2不同。temp_1等于悄悄把lag1变成lag2了。
高手给点解释?谢谢。(一个包子)。 |
|
m****r 发帖数: 202 | 20 try this
data orginal;
input id;
datalines;
1
2
3
4
;
data expect (keep=id);
set orginal;
do i=1 to 3;
id2=id;
output;
end;
run;
proc print;run; |
|
o****o 发帖数: 8077 | 21 data x;
input x;
m=int(log10(x))+1;
z=length(x);
y=x*10**(6-m);
datalines;
345
4567
777777
23567
;
run; |
|
f*****k 发帖数: 110 | 22 data trial (keep=x);
length x $6;
input x ;
y=count(x,' ') ;
i=1;
do while (i<=y);
x=trim(x)||'0';
i=i+1;
end;
datalines;
345
4567
777777
23567
;
run; |
|
f*****k 发帖数: 110 | 23 为嘛只得到空白而不是想要的结果呢?如何合理粗暴?
data trial ;
length x y $6;
input x ;
y=cats(x, '000000');
datalines;
345
4567
777777
23567
;
run;
WARNING: In a call to the CATS function, the buffer allocated
for the result was not long enough to contain the
concatenation of all the arguments. The correct result
would contain 11 characters, but the actual result may
either be truncated to 6 character(s) or be completely
blank, depending on the calling environment. The
... 阅读全帖 |
|
o****o 发帖数: 8077 | 24 data x;
input x $6.;
y=translate(x, '0', ' ');
datalines;
345
4567
777777
23567
;
run; |
|
k*******a 发帖数: 772 | 25 试试这个macro, 他把你所有数值型变量转化为对应的format,如果这个obs有至少一个'NA',
那么就设
置flag=1,否者flag=0
%macro flag(lib=, data=, out=);
proc sql;
select name, format, count(*) into
:var separated by ' ', :fmt separated by ' ', :n
from sashelp.vcolumn
where upcase(libname)=upcase("&lib") and
upcase(memname)=upcase("&data") and
type='num' and
format ne '';
quit;
data &out;
set &lib..&data;
flag=0;
%do i=1 %to &n;
if put(%scan(&var,&i), %scan(&fmt, &i, "' '")) = 'NA'
... 阅读全帖 |
|
j******o 发帖数: 127 | 26 孩子的代理有重复,你怎么编号?假如没有重复,可以试试下面:
data have;
input Child $ Guardian $;
datalines;
John David
John Mary
Ling Wang
Ling Peng
Ling Kevin
Lew Mike
;;
run;
proc sort data=have;
by child;
run;
data obtain(drop=G_number);
set have;
by child;
retain child_id;
if first.child then do;
child_id+1;
G_number=0;
end;
G_number +1;
Guardian_id=child_id*100+G_number;
format child_id z3. Guardian_id z5.;
run; |
|
w*******e 发帖数: 666 | 27 在SAS的官网上找到个链接,有画forest plot的code。
想请教:
如果sohn 2002 snow 1999 和raine2003 下还分别有A B C 三个race,该怎么修改上面
的code呢?
我试了半天,连input data都一直报错。
或者哪位在哪里看到相似的例子,能否发我一份呢?
非常感谢!
得出的图如下:
http://support.sas.com/kb/35/773.html
code 如下:
/* Set the graphics environment */
goptions reset=all cback=white border htitle=12pt htext=10pt;
... 阅读全帖 |
|
c*****t 发帖数: 1712 | 28 data x;
input x $ y $ z;
datalines;
a a 1
a a 2
b a 2
a c 1
;
run;
proc sort data=x; by x y;run;
proc means data=x noprint;
var z;
by x y;
output out=data1(drop=_type_ _freq_) sum=;
run;
proc sort data=data1; by y z;run;
data data2;set data1;by y; if last.y;run; |
|
t****g 发帖数: 35 | 29 An other way to do these:
data a;
input x $ y $ z;
datalines;
a a 1
a a 2
b a 2
a c 1
;
run;
Proc sort data=a;
by x y;
run;
data b (drop=z);
set a;
by x y;
if first.y=1 then t=0;
t+z;
if last.y;
end;
proc sort data=b;
by y t;
run;
data c;
set b;
by y t;
if last.y;
run; |
|
j******o 发帖数: 127 | 30 Does this work?
data have;
input x $ y $ z;
datalines;
a a 1
a a 2
b a 2
a c 1
;
run;
proc sql;
create table obtain as
select x, y, z
from (
select x, y, sum(z) as z
from have
group by x, y
)
group by y
having z=max(z);
quit; |
|
j******o 发帖数: 127 | 31 Try this.
data have;
input id x1 x2 x3 x4;
datalines;
1 0 7 8 .
2 6 8 1 0
3 . . . .
4 9 7 4 0
5 0 . . .
;
run;
data obtain;
set have;
array a{4} x1-x4;
t=0;
do i=1 to 4;
if not missing(a{i}) then t+1;
end;
if t ne 0;
drop t i;
run; |
|
k*******a 发帖数: 772 | 32 data a;
input value freq_1 freq_2;
datalines;
3 12 11
4 4 3
5 6 15
6 7 13
7 9 11
8 11 4
;
run;
proc sql;
select sum(value*freq_1)/sum(freq_1) as mean1, sum(value*freq_2)/sum(freq_2)
as mean2
from a;
quit; |
|
k*******a 发帖数: 772 | 33 data a;
input value freq_1 freq_2;
datalines;
3 12 11
4 4 3
5 6 15
6 7 13
7 9 11
8 11 4
;
run;
data b;
set a;
group=1;
freq=freq_1;
output;
group=2;
freq=freq_2;
output;
run;
proc ttest data=b;
var value;
class group;
freq freq;
run; |
|
k*******a 发帖数: 772 | 34 data a;
input ID A B C;
datalines;
1 1 0 1
2 0 1 0
3 . 1 0
4 0 1 .
5 . . 0
;
run;
proc transpose data=a out=b;
by id;
var a b c;
run;
proc freq data=b;
table col1*_name_;
run; |
|
c*****a 发帖数: 808 | 35 i don't know much. for my understanding,a dollar sign is needed in an input
statement if it is char
in the case of numeric, after reading data through the data step,you can use
'proc format' ( i think it is optional).
for example,
chd is binary
data heart;
input age chd;
datalines;
20 0
23 0
24 1
25 1
;
proc format;
value c 0 = 'No' 1 = 'Yes';
run;
proc catmod order=data;
direct age;
model chd = age /ml nogls pred =prob;
format chd c.;
run; |
|
a******a 发帖数: 743 | 36 想生成有两个column的gridded output 照着最简单的code写 出来怎么都是分成一张一
张的图 烦死了 大家帮个忙
有个很简单的sample code
data exp;
input age height weight;
datalines;
27 69 159
31 46 154
89 20 168
20 11 178
;
ods layout columns=2;
ods region;
proc gplot data=exp;
plot age*height; run;
ods region;
proc gplot data=exp;
plot age*weight; run;
ods layout end; |
|
l******r 发帖数: 12 | 37 A simple one
data have;
input a b formula $;
datalines;
2 3 a*b
5 56 a-b
;
run;
data _null_;
set have;
call symputx("formula",formula);
run;
data need;
set have;
d=&formula.;
run; |
|
P**********c 发帖数: 4 | 38 data temp;
input gender $;
datalines;
M
F
M
M
F
;
run;
data temp;
set temp;
if gender="M" then sex=1;
if gender="F" then sex=2;
run;
proc print data=temp;
run; |
|
a*****9 发帖数: 1315 | 39 I tried , gives me 3 obs
data a
input name $ age height;
if age LE 10;
datalines;
John McCloskey 35 71
June Rosesette 10 43
Tineke Jones 9 37
;
proc print data=test;
run;
but couldn't figure out why ? |
|
f******x 发帖数: 14 | 40 From your code, it will give you information:
OTE: Invalid data for age in line 5 6-14.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+
----7----+----8----+----9----+----0
5 John McCloskey 35 71
name=John age=. height=35 _ERROR_=1 _N_=1
NOTE: Invalid data for age in line 6 6-14.
6 June Rosesette 10 43
name=June age=. height=10 _ERROR_=1 _N_=2
NOTE: Invalid data for age in line 7 8-12.
7 Tineke Jones 9 37
name=Tineke age=. height=9 _ERROR_=1... 阅读全帖 |
|
s******r 发帖数: 1524 | 41 data test;
input Student $1. Score;
datalines;
A 90
A 91
B 88
B 85
B 93
C 88
C 95
;
run;
data test2;set test;by student;
if first.student then Raised=' ';
else if score>lag(score) then raised='Y';
else raised ='N';
run;
baozi pls. |
|
k*****u 发帖数: 1688 | 42 为什么“if _n_=1 then do until (last)”这一段中要用if _n_=1来判断呢?如果不
用的话,sum_x sum_y都是可以正确求出来,但是obs就是missing
请教一下这儿‘if _n_=1’起的什么作用?
data temp;
input x y@;
datalines;
1 2
3 4
5 6
. 9
6 7
7 .
1 8
6 3
;
run;
data q3;
if _n_=1 then do until (last);
set temp nobs=obs end=last;
sum_x+x;
sum_y+y;
end;
set temp;
if x=. then x=sum_x/obs;
if y=. then y=sum_y/obs;
run; |
|
D******n 发帖数: 2836 | 43 this way works, but stacking data is not that efficient. I came up with this
, just do more data manipulation on the means output.
----------------------------------------------->
data a1;
input x_1 y z weight;
datalines;
1 0 4 0.1
1 0 4 0.5
0 1 1 0.2
0 1 1 0.2
1 0 2 0.1
0 1 2 0.5
1 0 3 0.2
0 1 3 0.2
;
run;
proc means data=a1 noprint;
var x_1 y z;
weight weight;
output out=b sum= mean= nmiss=/autoname;
run;
proc transpose data=b(drop= _type_ _freq_) out=b2;run;
data b2;
... 阅读全帖 |
|
o****o 发帖数: 8077 | 44 也许可以试试PROC STDIZE
data a1;
input x_1 y z weight;
datalines;
1 0 4 0.1
1 0 4 0.5
0 1 1 0.2
0 1 1 0.2
1 0 2 0.1
0 1 2 0.5
1 0 3 0.2
0 1 3 0.2
;
run;
ods select none;
proc stdize data=a1 out=_null_ outstat=stat pctlpts=0 100;
var x_1 y z ;
weight weight;
run;
ods select all;
proc transpose data=stat out=stat2 ;
id _type_;
run;
痛。 |
|
z**o 发帖数: 149 | 45 For data a1:
data a1;
input x$ y1 y2 y3 y4;
datalines;
1 2 1 2 3
2 4 2 5 8
3 6 9 7 8
4 8 4 6 5
;
want to check if y1-yx =1 or not:
for _n_=1, I want to check if y1=1;
for _n_=2, I want to check if y1-y2=1;
for _n_=3, I want to check if y1-y3=1;
is there a way to put a value of one variable into another variable name?
like: array y(*) y1-y&x.; ?
Thanks a lot for BIG NIU!! |
|
p**3 发帖数: 2 | 46 "The answer is A" is correct ! Try removing and re-typing the datalines data
(no indenting) after copying and pasting. Run again and see what happens. |
|
a***e 发帖数: 1627 | 47 Perform a t-test of the null hypothesis that the means of the two groups are
equal.
Group 1: 39,40,32,60, 19,52,41,32, 13, 37, 28
Group 2: 70,47,54,27,31,42,37,41,9,18,33,23,49,41,59
但是sample size 不一样大,请问各位怎么写啊 ??
data hw;
input group $ blood @@;
datalines;
1 39 1 40 1 32 1 60 1 19 1 52 1 41 1 32 1 13 1 37 1 28
2 70 2 47 2 54 2 27 2 31 2 42 2 37 2 41 2 9 2 18 2 33 2 23 2 49 2 41 2 59
;
proc ttest data=hw;
by group;
var blood;
run;
可是为什么没有p-value 那些东西呢???
谢谢 |
|
q****k 发帖数: 1023 | 48 I have no problem to use SAS Proc Logistic for an input data with aggregate
"count" variable.
But in SPSS, for the same input data with "count" variable, how to get the
similar "freq count" statement for SPSS Logistic Regression?
Thanks!
Please refer to
http://support.sas.com/rnd/app/da/cat/samples/chapter8.html
data coronary;
input sex ecg ca count @@;
datalines;
0 0 0 11 0 0 1 4
0 1 0 10 0 1 1 8
1 0 0 9 1 0 1 9
1 1 0 6 1 1 1 21
;
run;
proc logistic des... 阅读全帖 |
|
D*******a 发帖数: 286 | 49 我有一组数据如下,因第二第三条记录的id缺省,想换成和第一条记录的id,我用lag
但是不行,那位高手能帮,谢了
data aa;
input id @3 vod mmddyy10. result $;
if id=. then id=lag1(id);
datalines;
1 08/11/2000 normal
. 09/23/2001 normal
. 03/01/2002 abnormal
2 05/21/2000 normal
. 04/22/2001 normal
. 11/12/2001 normal
;
run; |
|
k*******a 发帖数: 772 | 50 这种情况叫 last observation carry forward, 最好不要用lag改用retain
data aa;
retain lagid;
input id @3 vod mmddyy10. result $;
if id=. then id=lagid;
else lagid=id;
drop lagid;
datalines;
1 08/11/2000 normal
. 09/23/2001 normal
. 03/01/2002 abnormal
2 05/21/2000 normal
. 04/22/2001 normal
. 11/12/2001 normal
;
run; |
|