SAS let statement: refer to a cell value?

允我心安 提交于 2019-12-13 19:14:30

问题


In SAS, is it possible to refer a %let statement to a value located in a database?

For instance, the value of my n in %let n=50 depends on some value calculated in one of my databases, e.g., first row plus first column. And since that value gets modified 100 times in my loop I don't want to manually enter that value.


回答1:


There's several ways to do this. Here's two:

proc sql;
 select a+b into :n
 from your_table
 where some_condition;
quit;

This populations a macro variable, &n, with the sum of the variables a and b. The condition you specify should be true only for one row of your table.

Another approach:

data tmp;
 set your_table;
 if _n_=1 then do;
  call symputn('n',a+b);
 end;
run;


来源:https://stackoverflow.com/questions/11089896/sas-let-statement-refer-to-a-cell-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!