SAS:动态循环属性选择

时间:2013-06-27 06:38:32

标签: sas

我有一个具有多个属性的数据集,每个属性在主表中各有10-15行。我希望在数据集上使用do循环,这样我就可以单独提取每个属性的输出。我担心的是,一旦提取了前一个属性的输出,如何自动选择do循环中的属性?

提前感谢。

1 个答案:

答案 0 :(得分:0)

我不完全确定你要求做什么,但我希望能够展示do循环的基本思想。

%macro YOUR_MACRO();
   %let YOUR_VARIABLE = 1 2 3 ...;  /*This could be whatever you want to split up from your master table*/
   %let NUM_VAR = 3; /*Change this to the number of YOUR_VARIABLEs listed*/

   %do i = 1 %to &NUM_VAR. %by 1;
       %let LOOP_VAR = %scan(&YOUR_VARIABLE., %i.);
/*This do i = 1 starts your loop at 1 and goes up by 1 until your NUM_VAR is reached*/

proc sql;
    create table TABLE_&LOOP_VAR. as /*Creates a specific table for each variable*/
    select *
    from MASTER_TABLE
    where COLUMN_NAME = &LOOP_VAR. /*Splits up your table by a certain attribute equaling the loop variable*/
    ;
quit;

%end;
%mend;
%YOUR_MACRO(); /*Runs your loop*/

这是基本结构,应该给予一点帮助。您也可以只扫描主表中的每个变量名称,然后将其分开,而不必输入每个变量名称。