DATA Step, Macro, Functions and more

preserving (or adding single 'quotes') around a computed macro rolling date variable

Accepted Solution Solved
Reply
Contributor
Posts: 42
Accepted Solution

preserving (or adding single 'quotes') around a computed macro rolling date variable

All-

Due to the way our database is set up, I need to pull a weeks worth of data at a time in the format 'YYYY-MM-DD' and it has to be enclosed in single quotes.  I've never been really good at the whole reading or not reading those strange characters with macro variables so I thought I'd ask the experts!  I'm fairly certain this is an easy solution.

Here is what I have so far.  This gives me the two macro date variables &date1 and &date2.  However, I need to have single 'quotes' around them so that it resolves to '2013-01-28' and '2013-02-03' respectively.  I know I can't just put single quotes '&date1' and '&date2' like such but I'm not sure how to go about this.  Your input is always really appreciated! 

%let datem=today();

data _null_;

date1=put(intnx('week.2',&datem,-1,'b'),yymmddd10.);

date2=put(intnx('week.2',&datem,-1,'e'),yymmddd10.);

call symputx('date1',date1);

call symputx('date2',date2);

run;

%put &date1 &date2;


Accepted Solutions
Solution
‎02-06-2013 02:26 PM
Super Contributor
Posts: 578

Re: preserving (or adding single 'quotes') around a computed macro rolling date variable

%let datem=today();

data _null_;

date1=put(intnx('week.2',&datem,-1,'b'),yymmddd10.);

date2=put(intnx('week.2',&datem,-1,'e'),yymmddd10.);

call symputx('date1',"'"||date1||"'");

call symputx('date2',"'"||date2||"'");

run;

%put &date1 &date2;

View solution in original post


All Replies
Solution
‎02-06-2013 02:26 PM
Super Contributor
Posts: 578

Re: preserving (or adding single 'quotes') around a computed macro rolling date variable

%let datem=today();

data _null_;

date1=put(intnx('week.2',&datem,-1,'b'),yymmddd10.);

date2=put(intnx('week.2',&datem,-1,'e'),yymmddd10.);

call symputx('date1',"'"||date1||"'");

call symputx('date2',"'"||date2||"'");

run;

%put &date1 &date2;

Contributor
Posts: 42

Re: preserving (or adding single 'quotes') around a computed macro rolling date variable

Works like a charm!  Thanks so much for the quick reply.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 498 views
  • 0 likes
  • 2 in conversation