使用PROC SQL为列创建保留列表(Use PROC SQL to create keep list for columns)

我需要选择名称包含字符串'_fire'的列。 名称可以通过语句选择获得

proc sql; create table x as select _name_ from work.x where lowcase(_name_) like '%_fire' ;quit;

但我不知道,接下来该怎么办? 我尝试将此数据插入变量,但后来我得到错误:KEEP选项的值无效。

proc sql noprint; select _name_ into :names from work.x where lowcase(_name_) like '%_fire'; quit; DATA twowks1 ; SET work.&tabulka. (KEEP = &names. ) ; RUN;

谁能帮我? 谢谢

i need select colums whose names contains string '_fire'. Names can be obtained by statement select

proc sql; create table x as select _name_ from work.x where lowcase(_name_) like '%_fire' ;quit;

But i dont know, what to do next? I tried insert this data into variable, but then i get error: Invalid value for the KEEP option.

proc sql noprint; select _name_ into :names from work.x where lowcase(_name_) like '%_fire'; quit; DATA twowks1 ; SET work.&tabulka. (KEEP = &names. ) ; RUN;

can anyone help me? Thx

最满意答案

您在PROC SQL查询中缺少separated by符。 但是,当&Names不存在时,我只会收到您的错误,因此您的SQL查询是否有错误?

*To generate your error; %symdel names; DATA twowks1; SET work.&tabulka. (KEEP=&names.); RUN;

这是一些有用的,因为你可能期待。

*Works as expected; proc sql noprint; select _name_ into :names separated by " " from work.x where lowcase(_name_) like '%_fire'; quit; DATA twowks1; SET work.&tabulka. (KEEP=&names.); RUN;

You're missing the separated by in your PROC SQL query. However, I only get your error when &Names does not exist, so is there an error with your SQL Query?

*To generate your error; %symdel names; DATA twowks1; SET work.&tabulka. (KEEP=&names.); RUN;

Here is some that works as you're probably expecting.

*Works as expected; proc sql noprint; select _name_ into :names separated by " " from work.x where lowcase(_name_) like '%_fire'; quit; DATA twowks1; SET work.&tabulka. (KEEP=&names.); RUN;

更多推荐