BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11
%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 

3 REPLIES 3
Kurt_Bremser
Super User

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;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

BrunoMueller
SAS Super FREQ

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

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 652 views
  • 2 likes
  • 4 in conversation