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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
sasthebest
Calcite | Level 5

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

5 REPLIES 5
Reeza
Super User

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?

Anotherdream
Quartz | Level 8

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?

sasthebest
Calcite | Level 5

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!!

Anotherdream
Quartz | Level 8

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".

Reeza
Super User

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 5 replies
  • 1259 views
  • 0 likes
  • 3 in conversation