Re: [問題] sas 有關if的問題,拜託高手幫忙
data temp;
input t @@;
cards;
1 2 3 4 5 6 7 8 9
;
run;
data test(keep=print);
length print $50;
set temp;
if t<2 then
do;
s1=t*t;
print='t<2, s1='|| left(s1);
end;
else if 2<=t<=4 then
do;
s1=t*t ;
s2= s1*t;
print='2<=t<=4, s1=' || trim(left(s1)) || ' ,s2=' || trim(left(s2)) ;
end;
else
do;
s1=t*t ;
s2= s1*t;
s3=s2*t;
print='t>4, s1=' || trim(left(s1)) || ' ,s2=' ||
trim(left(s2)) || ' ,s3=' || trim(left(s3));
end;
run;
---
不確定這是不是你想要的東西XD
test檔裡面的東西就是平常c print出來的東西
s1 s2 s3後面的式子自行修改
然後print的東西空格逗號什麼的排版再微調一下就行了
如果t不是要顯示t而是想要顯示1~9的話把t像s1 s2 s3那樣切開來串就行了
※ 引述《ejiuhp (FUTURE)》之銘言:
: 因為我看了sas的help說明,還是無法將我想表達的寫成sas,但我要表達的內容用c語言寫
: 是下面那段,我想把他寫成sas語言要怎麼寫?
: 其實我要表達的東西就是有s1 s2 s3 三個式子,而我想要在
: if t<2 then do s1 ;
: if t>=2 and t<4 then do s1 s2 ;
: if t >=4 then do s1 s2 s3;
: 然後都要print 出來
: t<2
: t<2
: t<2
: 2<t<4
: 2<t<4
: 2<t<4
: t>4
: t>4
: .
: .(t為0到9)
: 但我不會寫,
: 以下為c語言寫法不知道各位高手會不會改成sas。
: for ( t =0 ; t<=9 ; t++ ){
: if ( t< 2){
: s1== (1+((b1*(X11t-127.3)))*((1-exp(-(p+q)*t)/1+(p/q)*exp(-(p+q)*t
: ))*m1*(1-(1-exp(-(p+q)*(t-2)))/(1+(p/q)*exp(-(p+q)*(t-2))))))
: printf("t<2, s1= %d",s1)
: };
: else if ( 2<=t< =4){
: s2 = (1+((b1*(X12t-67.8)))*((1-exp(-(p+q)*(t-2)))/(1+(p/q)*exp(
: -(p+q)*(t-2)))*(m2+m1*(1-exp(-(p+q)*t)))/(1+(p/q)*exp(-(p+q)*t))
: *(1-(1-exp(-(p+q)*(t-4)))/(1+(p/q)*exp(-(p+q)*(t-4))))));
: printf("2<t<4, s1= %d ,s2=%d,s1,s2); ...
: };
: else
: s1== (1+((b1*(X11t-127.3)))*((1-exp(-(p+q)*t)/1+(p/q)*exp(
: -(p+q)*t))*m1*(1-(1-exp(-(p+q)*(t-2)))/(1+(p/q)*exp(-(p+q)*(t-2))))));
: s2 = (1+((b1*(X12t-67.8)))*((1-exp(-(p+q)*(t-2)))/(1+(p/q)*exp(-(p+q)*
: (t-2)))*(m2+m1*(1-exp(-(p+q)*t)))/(1+(p/q)*exp(-(p+q)*t))*
: (1-(1-exp(-(p+q)*(t-4)))/(1+(p/q)*exp(-(p+q)*(t-4))))));
: S3 = (1+((b1*(X13t-63.7)))*((1-exp(-(p+q)*(t-4)))/(1+(p/q)*
: exp(-(p+q)*(t-4))))*(m3+((1-(1-exp(-(p+q)*(t-2))))/(1+(p/q)*
: exp(-(p+q)*(t-2)))))*(m2+m1*(1-exp(-(p+q)*t)/(1+(p/q)*exp(-(p+q)*t)))));
: printf("t>4, s1= %d ,s2=%d,s3=%d,s1,s2,s3);
: }
: };
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.109.40.59
※ 編輯: west1996 來自: 140.109.40.59 (11/24 15:50)
推
11/24 16:43, , 1F
11/24 16:43, 1F
→
11/24 17:10, , 2F
11/24 17:10, 2F
→
11/24 17:11, , 3F
11/24 17:11, 3F
→
11/24 17:11, , 4F
11/24 17:11, 4F
→
11/24 17:12, , 5F
11/24 17:12, 5F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):