%let whr=%str(where randfl="Y" and ASATFL="Y" and DCTRTDT=. and dthdt=. and missing(DCSTYDT));
proc sql;
create table aaa as
select count(distinct usubjid) as nobs
from adsl
&whr;
quit;
Dear ,
In my code, when i used dot for missing values the below code is not working, but when i used missing function it works. Which one should i use in place of %str when i use DOT. Thank you
In my code, DCTRTDT=. and dthdt=. are not resolving, but missing(DCSTYDT) is resolving
No masking is needed, see this example:
data have;
set sashelp.class;
if mod(_n_,2) = 1 then age = .;
run;
%let whr=where age = . and substr(name,1,1) = 'J';
proc sql;
create table want as
select * from have
&whr
;
quit;
Why pass SAS code in via macros in the first place? SAS code can contain all kinds of special characters, quotes etc. which will mess up your code. There are much better ways of doing things. For example, if your macro or code needs that data filtered, create a new dataset which is already filtered, then pass that filtered data into your macro. The coding then is very simple Base SAS, and passing of SAS code is not needed. Your just obfuscating your code for no benefit.
Since the text in your macro variable is quoted, you need to unquote it when it is used. See example below
data have;
set sashelp.class;
if mod(_n_,2) = 1 then age = .;
run;
%let whr= %str(where age = . and substr(name,1,1) = 'J');
proc sql;
create table want as
select * from have
%unquote(&whr)
;
quit;
thanks @Kurt_Bremser for the sample
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: