[英]How can I create custom macro variables using a macro and sas proc sql into?
%macro get_names_into_macvar(name1=,into1=);
proc sql;
select name into :&into1 separated by ' '
from column_names
where UPCASE(name) contains upcase("&name1");
;
quit;
%mend;
%get_names_into_macvar(name1=topic1, into1=topic1macvar);
%get_names_into_macvar(name1=topic2, into1=topic2macvar);
I have a very large data set with an insane amount of columns that follow a simple format. 我有一个非常大的数据集,其中包含遵循简单格式的大量列。 Each column represents a topic and a different metric for that topic. 每列代表一个主题以及该主题的不同指标。 The column names look like topic1_metric1, topic1_metric2 ...., topic5_metric15, ... topic20_metric1 列名称看起来像topic1_metric1,topic1_metric2 ....,topic5_metric15,... topic20_metric1
What I would like is to get a list of all column names for each given topic (or metric) and store that in a macro variable for future use. 我想要获取每个给定主题(或指标)的所有列名称的列表,并将其存储在宏变量中以备将来使用。 I already created the table of column names from the dictionary table. 我已经从字典表创建了列名表。 When I run the above sql code on its own, it works ... but copy and pasting and changing the topic names can't be the most efficient way to accomplish this. 当我自己运行上述sql代码时,它可以工作...但是复制,粘贴和更改主题名称并不是实现此目的的最有效方法。
proc sql;
select name into :topic1macvar separated by ' '
from column_names
where UPCASE(name) contains upcase("topic1");
;
quit;
My problem lies in creating custom macro variables to store it per topic. 我的问题在于创建自定义宏变量以按主题存储它。
select name into :&into1 separated by ' '
The above section of the code is not resolving into a macro variable. 上面的代码部分没有解析为宏变量。 What am I doing wrong? 我究竟做错了什么?
Most likely your trouble is that you are making local macro variables that disappear when the macro ends. 最有可能的麻烦是您正在使局部宏变量在宏结束时消失。
%macro get_names_into_macvar(name1=,into1=);
%if not %symexist(&into1) %then %global &into1 ;
proc sql noprint;
select name into :&into1 separated by ' '
from column_names
where UPCASE(name) contains %upcase("&name1")
;
quit;
%mend;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.