在SAS中循环字符值 [英] looping over character values in SAS
本文介绍了在SAS中循环字符值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 Stata 中,您可以使用 foreach 命令遍历字符值列表.到目前为止,我一直在尝试在 SAS 中做同样的事情,但无济于事.我正在尝试对字符列的所有值运行一系列数据和 proc 语句.我尝试了以下方法:
In Stata you can loop over a list of character values with the foreach command. I've been trying to do the same in SAS to no avail so far. I'm trying to run a series of data and proc statements over all the values of character column. I tried with the following:
%let mylist = a b c; * These are all the values of a column called "code";
data mydata_@mylist; * Each element creates a new table;
set mydata;
where code=&mylist;
run;
我做错了什么或错过了什么?
What am I doing wrong or missing?
提前致谢,
马蒂亚斯
推荐答案
试试这个:
%macro loopit(mylist);
%let n = %sysfunc(countw(&mylist));
%do I=1 %to &n;
%let val = %scan(&mylist,&I);
data mydata_&val;
set mydata;
where code = "&val";
run;
%end;
%mend;
%let list=a b c;
%loopit(&list);
这篇关于在SAS中循环字符值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文