Desktop productivity for business analysts and programmers

Extracting Data from set of dates

Reply
Occasional Contributor
Posts: 8

Extracting Data from set of dates

Hello,

 

I am using Proc SQL to extract data from the DB. However, rather that a range of data (i.e between X and Y), i would like to extract it from multiple dates.

 

I would like to use

%LET DATES = ('21-JUN-2016'd',22-jul-2016'd,'21-NOV-2016'd,'21-dec-2016'd);

 

Instead of this:

%LET BEGDT = '01-jul-2016'd;

%LET ENDDT = '31-dec-2016'd;

 

 

 

Super User
Super User
Posts: 7,955

Re: Extracting Data from set of dates

Your code is invalid, containing unbalanced quote marks:

%LET DATES = ('21-JUN-2016'd',22-jul-2016'd,'21-NOV-2016'd,'21-dec-2016'd);

                                                               ^

 

Secondly, is this the type of "date" that your database is expecting?  Its likely that the DB stores dates differently to SAS, do you have some working code?

 

Next up the usual advice, put data into a dataset:

 

data dvals;
  d='21jun2016'd; output;
  d='22jul2016'd; output;
...
run;

This way you can then do:

 

proc sql;
  select *
  from    HAVE
  where  DATE in (select * from DVALS);
quit;
Super User
Posts: 7,782

Re: Extracting Data from set of dates

So you want

%LET DATES = ('21-JUN-2016'd,'22-jul-2016'd,'21-NOV-2016'd,'21-dec-2016'd);

proc sql;
select ....
from .....
where date in &dates
;
quit;

?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 8

Re: Extracting Data from set of dates

Posted in reply to KurtBremser
Super User
Posts: 7,782

Re: Extracting Data from set of dates


SASd15 wrote:

Yes @KurtBremser


So where is the question then?

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 8

Re: Extracting Data from set of dates

Posted in reply to KurtBremser

My apologies, not sure why the proc sql didn't work for me initially. I thought i was using an incorrect syntax.

 

Thanks!

Ask a Question
Discussion stats
  • 5 replies
  • 148 views
  • 0 likes
  • 3 in conversation