BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lizzy28
Quartz | Level 8

Hi everyone,

 

This is a similar question to what I posted last time.

 

I tried plug in a date macro variable (&curdat_2mon as in the code below) in my query. But it looks the quote (%str(%')) I used is not right? Can anyone help me correct again? If there is a simplified way to use the macro variable in the query, that would be great too. Thanks a lot!

 

data _null_;

curdat_2m = intnx('Month',"&sysdate"d,-2,'s');

call symput ('curdat_2mon',put(curdat_2m,date9.)) ;

run;

%put &curdat_2mon ;

PROC SQL;

CREATE TABLE new_tbl as

select distinct MBR_ID, FST_NM, LST_NM, DOB, ZIP

from DB.MBR_TBL

where  %str(%')&curdat_2mon.%str(%')d

between BEG_DT and END_DT

;

QUIT;

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Either don't apply the format, the easiest method, or in your usage of the variable just use double quotes.

 

PROC SQL;
CREATE TABLE new_tbl as
select distinct MBR_ID, FST_NM, LST_NM, DOB, ZIP
from DB.MBR_TBL
where  "&curdat_2mon"d
between BEG_DT and END_DT
;

Easier:

data _null_;
curdat_2m = intnx('Month',"&sysdate"d,-2,'s');
call symput ('curdat_2mon',curdat_2m) ;
run;

%put &curdat_2mon ;

PROC SQL;
CREATE TABLE new_tbl as
select distinct MBR_ID, FST_NM, LST_NM, DOB, ZIP
from DB.MBR_TBL
where  &curdat_2mon.
between BEG_DT and END_DT
;
QUIT;

 

View solution in original post

3 REPLIES 3
Reeza
Super User

Either don't apply the format, the easiest method, or in your usage of the variable just use double quotes.

 

PROC SQL;
CREATE TABLE new_tbl as
select distinct MBR_ID, FST_NM, LST_NM, DOB, ZIP
from DB.MBR_TBL
where  "&curdat_2mon"d
between BEG_DT and END_DT
;

Easier:

data _null_;
curdat_2m = intnx('Month',"&sysdate"d,-2,'s');
call symput ('curdat_2mon',curdat_2m) ;
run;

%put &curdat_2mon ;

PROC SQL;
CREATE TABLE new_tbl as
select distinct MBR_ID, FST_NM, LST_NM, DOB, ZIP
from DB.MBR_TBL
where  &curdat_2mon.
between BEG_DT and END_DT
;
QUIT;

 

Quentin
Super User

I would suggest using double quotes:

where "&curdat_2mon"d
between BEG_DT and END_DT
;

That avoids the need to %STR() for macro quoting.

 

 

If you really want to use single quotes, it should work if you %unquote it yourself, e.g.:

where  %unquote(%str(%')&curdat_2mon.%str(%')d)
between BEG_DT and END_DT
;

 

The macro processor sometimes failes to unquote code automatically.

BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
lizzy28
Quartz | Level 8
Thanks a lot, Reeza and Quentin!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3779 views
  • 2 likes
  • 3 in conversation