DATA Step, Macro, Functions and more

Dates with Quotes as Macro variables

Reply
Occasional Contributor RHL
Occasional Contributor
Posts: 9

Dates with Quotes as Macro variables

I'm trying to create a macro variable in the form of 'yyyy-mm-dd' to pass to a DB2 query in a PROC SQL pass-thru query.

I use the following code to get the date, but don;t know how to include the quotes that DB2 requires.

data _null_;
filedate = today() - 1;
filedt = put(filedate,yymmdd10.);
call symput('fdate',filedt);
run;

Can anybody show me how to come up with a macro variable that includes the quotes?

Thanks.
Super Contributor
Super Contributor
Posts: 3,174

Re: Dates with Quotes as Macro variables

Use a concatenation in your CALL SYMPUT so you surround the "formatted" date, as shown below (I use asterisks, not vertical bars for a concatenation - no default codepage problem when sending code via FTP)):

data _null_;
CALL SYMPUT('myvar','"' !! put(today(),yymmdd10.) !! '"');
run;
%put &myvar;

Scott Barry
SBBWorks, Inc.
Occasional Contributor RHL
Occasional Contributor
Posts: 9

Re: Dates with Quotes as Macro variables

Thanks. That really helped. It's amazing how simple the solution is to a problem I've tried to solve the whole afternoon!
PROC Star
Posts: 1,561

Re: Dates with Quotes as Macro variables

Also,
[pre]
data _null_;
CALL SYMPUT('myvar',quote(put(today(),yymmdd10.)));
run;
Ask a Question
Discussion stats
  • 3 replies
  • 144 views
  • 0 likes
  • 3 in conversation