首页 > 解决方案 > 如何在proc sql的where子句中使用宏变量

问题描述

例如,我有:

%let state_exclude = Michigan Maine Minnesota;
proq sql;
   create table States
   select state
   from geography_dim as geo
   where geo.country="US" and geo.state ~= "&state_exclude"
quit;

它返回零行,我认为这是因为我在那里使用宏变量但我不知道如何修复它

标签: sqlsas

解决方案


我不是美国人,难道是“Michigan Maine Minnesota”三个独立的地方?如果是这样,您应该使用inoperator 而不是=. 例如:

%let state_exclude = "Michigan" "Maine" "Minnesota"; 
proq sql; 
  create table States as
  select state from geography_dim
  where country="US" and state not in (&state_exclude);
quit;

推荐阅读