我正在尝试在SAS中编写一个PROC SQL查询,以确定以特定字母开头的多个列的最大值(比如RF *)。现有的proc意味着我已经这样说了。
proc means data = input_table nway noprint missing;
var age x y z RF: ST: ;
class a b c;
output out = output_table (drop = _type_ _freq_) max=;
run;
列RF:指的是以RF开头的所有列,同样也指ST。我想知道在PROC SQL中是否有类似的东西,我可以使用它?
谢谢!
答案 0 :(得分:1)
如果必须使用SQL,那么动态SQL确实是这样做的。好消息是你可以只使用一个宏变量在一个proc sql调用中完成所有操作,例如:
proc sql noprint;
select catx(' ','max(',name,') as',name) into :MAX_LIST separated by ','
from dictionary.columns
where libname = 'SASHELP'
and memname = 'CLASS'
and type = 'num'
/*eq: is not available in proc sql in my version of SAS, but we can use substr to match partial variable names*/
and upcase(substr(name,1,1)) in ('A','W') /*Match all numeric vars that have names starting with A or W*/
;
create table want as select SEX, &MAX_LIST
from sashelp.class
group by SEX;
quit;