2016-11-25 65 views
0

我想使用“select into”来创建SAS中所有ID的列表。简单的SAS选择到

/* my state table try01 */ 
data try01; 
input id state $; 
cards; 
1108 va 
1102 dc 
1101 md 
1105 on 
; 

run; 

/* select into */ 
proc sql noprint; 
select id into: x from try01; 
quit; 

%put &x; 

我的问题是,为什么日志显示宏x是只有一个值(1108),而不是一个列表(1108,1102,1101,1105)的 ?如此困惑......非常感谢。

+0

'into'将该值放入标量变量中。你为什么期望一个列表? –

+0

,因为sql子句select id的结果返回一个列表(1108,1102,1101,1105)。所以宏观x应该也是一个列表。我错了吗? – sincerelyurs

回答

3

如果您希望SQL将多个值放入宏变量,则需要包含SEPARATED BY子句。

select id into :x separated by ' ' from try01; 

然后,您可以使用此列表中,例如IN话务员呼叫。

proc print data=have ; 
    where id in (&x); 
run; 
+0

非常感谢汤姆!问题解决了!^__ ^ – sincerelyurs