/*test data*/
data geography_dim ;
states="Aaaaa";profit=10;output;
states="Naaaa";profit=10;output;
run;
/*set macro variable*/
%let M=N;
/*check if you want*/
%put "&M";
/*your case in datastep*/
data test;
set geography_dim;
if substr(states,1,1) eq "&M" then profit=profit*10;
else profit=0;
run;
/* results
states profit
Aaaaa 0
Naaaa 100
*/
2条答案
按热度按时间nbnkbykc1#
为了便于讨论,假设您更改了宏变量的名称
M
更可笑的表达,例如YN_OPTION_SELECT_M_STATES
```%let YN_OPTION_SELECT_M_STATES = N;
proc sql;
select states,profit,
case
when .....
else
end
from geography_dim
/* add this */
where
("&YN_OPTION_SELECT_M_STATES" eq 'N' & STATE not like 'M%')
or
("&YN_OPTION_SELECT_M_STATES" ne 'N' & STATE like 'M%')
;
quit;
41zrol4v2#
它不是sql,但在datastep中非常简单。如果您想用m宏值检查起始值,在这种情况下为“n”,您可以这样做: