Creating list of date macros

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 18
Accepted Solution

Creating list of date macros

I am trying to get to this with my macro. Can anyone help?

'1jan2012'd','1jan2013'd','1jan2014'd','1jan2015'd','1jan2016'd',

data want;

  informat Date_of_Birth mmddyy10.;

  format Date_of_Birth mmddyy10.;

  input Date_of_Birth;

  cards;

1/1/2012

1/1/2012

1/1/2013

1/1/2013

1/1/2014

1/1/2014

1/1/2015

1/1/2015

1/1/2016

1/1/2016

;

Run;

proc sql noprint;

  select distinct cats("'"(put(Date_of_Birth format,date9.))  

        into :date  separated by ','

  from want

;

quit;

%put &date;


Accepted Solutions
Solution
‎08-14-2013 12:30 AM
Occasional Contributor
Posts: 18

Re: Creating list of date macros

Posted in reply to Anotherdream

first let me correct my question. this is what I wanted:

'1jan2012'd,'1jan2013'd,'1jan2014'd,'1jan2015'd,'1jan2016'd.

and not this:

'1jan2012'd','1jan2013'd','1jan2014'd','1jan2015'd','1jan2016'd',

Then goal is to use it in something like this:

data test;

set want;

where Date_of_Birth in (&date);

run;

You answer gives me what I wanted.

select distinct "'"||put(date_of_birth,date9.)||"'d'" into :date separated by ','

Appreciate it!!

View solution in original post


All Replies
Super User
Posts: 19,777

Re: Creating list of date macros

Posted in reply to sasthebest

Why do you need the dates quoted?

What are you trying to do? SAS will use the numerical dates for comparison, so you many not need to format it depending on what you're doing?

Super Contributor
Posts: 418

Re: Creating list of date macros

Posted in reply to sasthebest

proc sql;

select distinct "'"||put(date_of_birth,date9.)||"'d'" into :date separated by ','

from want;

quit;

run;

%put &date;

The above works, but in short, why do you want this? This is a very strange request because you have an uneven number of strings, and having the string around the d at the end (the last quote at the end of each string) does not seem necessary.

Furthermore, why do you want this in general? What is the overall purpose?

Solution
‎08-14-2013 12:30 AM
Occasional Contributor
Posts: 18

Re: Creating list of date macros

Posted in reply to Anotherdream

first let me correct my question. this is what I wanted:

'1jan2012'd,'1jan2013'd,'1jan2014'd,'1jan2015'd,'1jan2016'd.

and not this:

'1jan2012'd','1jan2013'd','1jan2014'd','1jan2015'd','1jan2016'd',

Then goal is to use it in something like this:

data test;

set want;

where Date_of_Birth in (&date);

run;

You answer gives me what I wanted.

select distinct "'"||put(date_of_birth,date9.)||"'d'" into :date separated by ','

Appreciate it!!

Super Contributor
Posts: 418

Re: Creating list of date macros

Posted in reply to sasthebest

glad to hear it, but just as an fyi, sas stores dates as numbers. Therefore, in your where clause, if your variable date_Of_birth is an actual date, you can just imput the Numberic format of each of these dates and it will work the same (plus be a heck of a lot easier).

Just my 2 cents, but glad I could "help".

Super User
Posts: 19,777

Re: Creating list of date macros

Posted in reply to sasthebest

As a followup to anotherdream's comment the following would also work, with your macro variable in the where clause.

data want;

  informat Date_of_Birth mmddyy10.;

  format Date_of_Birth mmddyy10.;

  input Date_of_Birth;

  cards;

1/1/2012

1/1/2012

1/1/2013

1/1/2013

1/1/2014

1/1/2014

1/1/2015

1/1/2015

1/1/2016

1/1/2016

;

Run;

proc sql noprint;

  select distinct Date_of_Birth format=best8.  

        into :date  separated by ','

  from want

;

quit;


data test;

set want;

where Date_of_Birth in (&date);

run;

🔒 This topic is solved and locked.

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

Discussion stats
  • 5 replies
  • 350 views
  • 0 likes
  • 3 in conversation