由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - 在SAS里如何用array或者macro改进这段程序?求指教!
相关主题
弱问一个SAS里面求adjusted means的问题SAS BASE 官方sample 第三题 求解析 谢谢!
help!! help!! SAS help!! Urgent!!Ask 2 simple SAS questions,thanks
请问SAS中如何通过组内一个变量的值控制整组变量A SAS question
How to change sas dataset column orderSAS help
请问如果用SAS 解决这个问题请教一个简单SAS问题
help about initial value in retain statement[急求助] survival analysis (SAS)
请教proc sql处理missing value的问题关于stepwise programming
包子问题请教( sas)请问sas中一个变量的内容被两个左斜杠(/)分成了三部分
相关话题的讨论汇总
话题: var4话题: var1话题: target话题: array话题: steroid
进入Statistics版参与讨论
1 (共1页)
t********m
发帖数: 939
1
if var1 in ('x','y','z') or var2 in ('x','y','z') or var3 in ('x','y','z
') or var4 in ('x','y','z') then target=1; else target=0;
就是只要var1-var4里面任何一个变量含有x或y或z,目标变量就等于1,否则为0。
上述程序很繁琐,能不能用array来优化一下啊?多谢指教!
t*******t
发帖数: 633
2
这个可以啵?
data test;
input var1 $ var2 $ var3 $ var4 $ var5;
cards;
x 8 2 1 4
3 4 5 21 2
0 z 88 45 2
;
run;
data test2;
set test;
array var{4} var1-var4;
do i=1 to 4;
if var{i} in ('x','y','z') then target=1;
end;
if missing(target) then target=0;
run;
c******n
发帖数: 380
3
if indexc(catx('',of var1-var4),'xyz')>0 then target=1;else target=0
s******r
发帖数: 1524
4
You assume var1-var4 is one-letter variable. It may not be true.

【在 c******n 的大作中提到】
: if indexc(catx('',of var1-var4),'xyz')>0 then target=1;else target=0
c******n
发帖数: 380
5

It is true according to LZ's codes, not words.
Even if it is not true, why would my code not work?

【在 s******r 的大作中提到】
: You assume var1-var4 is one-letter variable. It may not be true.
s******r
发帖数: 1524
6
if var1 in ('x','y','z') or var2 in ('x','y','z') or var3 in ('x','y','z
') or var4 in ('x','y','z')
does not mean var1-var4 is one-letter variable. It could be
'xag','x','yz'.
So only the second one meets LZ's requirement.

【在 c******n 的大作中提到】
:
: It is true according to LZ's codes, not words.
: Even if it is not true, why would my code not work?

c******n
发帖数: 380
7

'z
I see, you're right.

【在 s******r 的大作中提到】
: if var1 in ('x','y','z') or var2 in ('x','y','z') or var3 in ('x','y','z
: ') or var4 in ('x','y','z')
: does not mean var1-var4 is one-letter variable. It could be
: 'xag','x','yz'.
: So only the second one meets LZ's requirement.

t********m
发帖数: 939
8
这个works,非常感谢!我自己写的时候,没用missing function,而是用了下面的if.
..else,所以逻辑怎么都搞不对,要么是不加output,只输出最后的var4满足条件的
records;要么就是加output,最后每个var满足的records都被输出了,其中难免有重
复的。Thanks again!
data test;
set test;
array var(4) var1-var4;
do i=1 to 4;
if drugid(i) in ('x','y','z') then steroid=1;
else steroid=0;
*output;
end;
run;

【在 t*******t 的大作中提到】
: 这个可以啵?
: data test;
: input var1 $ var2 $ var3 $ var4 $ var5;
: cards;
: x 8 2 1 4
: 3 4 5 21 2
: 0 z 88 45 2
: ;
: run;
: data test2;

t********m
发帖数: 939
9
你说的很对,我的variables确实不是one-letter的。

【在 s******r 的大作中提到】
: You assume var1-var4 is one-letter variable. It may not be true.
t********m
发帖数: 939
10
谢谢,但是正如“无限江山”大侠说的,我的variables的确不是one-letter的,所以
你的code不太合适。但还是要感谢你,以后碰到单字母variable就知道用这个啦!

【在 c******n 的大作中提到】
: if indexc(catx('',of var1-var4),'xyz')>0 then target=1;else target=0
相关主题
help about initial value in retain statementSAS BASE 官方sample 第三题 求解析 谢谢!
请教proc sql处理missing value的问题Ask 2 simple SAS questions,thanks
包子问题请教( sas)A SAS question
进入Statistics版参与讨论
t********m
发帖数: 939
11
Thanks, everyone! 高手在mitbbs啊,呵呵~
s******r
发帖数: 1524
12
Your code could work after a little change.
data test;
set test;
array drugid(4) var1-var4;
steroid=0;
do i=1 to 4;
if drugid(i) in ('x','y','z') then steroid=1;
end;
if steroid=0 then delete;
drop i;
run;

if.

【在 t********m 的大作中提到】
: 这个works,非常感谢!我自己写的时候,没用missing function,而是用了下面的if.
: ..else,所以逻辑怎么都搞不对,要么是不加output,只输出最后的var4满足条件的
: records;要么就是加output,最后每个var满足的records都被输出了,其中难免有重
: 复的。Thanks again!
: data test;
: set test;
: array var(4) var1-var4;
: do i=1 to 4;
: if drugid(i) in ('x','y','z') then steroid=1;
: else steroid=0;

m*****a
发帖数: 658
13
I think this is interesting one. Could you tell me why catx function have to
be used here?
Thanks,

【在 c******n 的大作中提到】
: if indexc(catx('',of var1-var4),'xyz')>0 then target=1;else target=0
c******n
发帖数: 380
14

to
I don't think I understand your question. Are you asking why not using other
concatenate functions?

【在 m*****a 的大作中提到】
: I think this is interesting one. Could you tell me why catx function have to
: be used here?
: Thanks,

m*****a
发帖数: 658
15
I mean why f indexc(of var1-var4,'xyz)>0 then target=1;else target=0 ,
doesnt work ?
c******n
发帖数: 380
16

见6楼回复

【在 m*****a 的大作中提到】
: I mean why f indexc(of var1-var4,'xyz)>0 then target=1;else target=0 ,
: doesnt work ?

1 (共1页)
进入Statistics版参与讨论
相关主题
请问sas中一个变量的内容被两个左斜杠(/)分成了三部分请问如果用SAS 解决这个问题
怎样用R定位变量的位置help about initial value in retain statement
怎样用R除掉DUPLICATED RECORD请教proc sql处理missing value的问题
[合集] └ Re: 关于stepwise programming包子问题请教( sas)
弱问一个SAS里面求adjusted means的问题SAS BASE 官方sample 第三题 求解析 谢谢!
help!! help!! SAS help!! Urgent!!Ask 2 simple SAS questions,thanks
请问SAS中如何通过组内一个变量的值控制整组变量A SAS question
How to change sas dataset column orderSAS help
相关话题的讨论汇总
话题: var4话题: var1话题: target话题: array话题: steroid