BookmarkSubscribeRSS Feed
temsandroses
Calcite | Level 5

I am trying to pull data from oracle based on the 3 columns from the input file:

 

start_date| end_date | title

01aug2021 | 01oct2021| 2021 Batch 1

01jul2021 | 01oct2021| 2021 Batch 2

01jun2021 | 01oct2021| 2021 Batch 3

 

For each title I want to obtain data for each day only within the start and end date.

 

Is there a way to do so?

2 REPLIES 2
SASJedi
Ammonite | Level 13

This worked for me:

Setup some test data:

 

data have;
   infile datalines dsd dlm='|';
   input start_date:date9. end_date:date9. title:$50.;
   format start_date end_date date9.;
datalines;
01aug2021 | 01oct2021| 2021 Batch 1
01jul2021 | 01oct2021| 2021 Batch 2
01jun2021 | 01oct2021| 2021 Batch 3
;

libname db oracle user=student pw=Metadata0;
data db.Titles;
   if _n_=1 then call streaminit(12345);
   set have;
   output;
   do i= 1 to rand('integer',1,5);
      start_date=sum(start_date,rand('integer',1,5));
      end_date=sum(start_date,rand('integer',1,3));
      output;
   end;
   drop i;
run;

Then this SQL join did the trick:

 

 

proc sql;
select db.* 
   from work.have as h
        inner join 
        db.Titles as db
        on db.title=h.title
          and datepart(db.start_date)=h.start_date
          and datepart(db.end_date)=h.end_date
   ;
quit;

 

 

START_DATE END_DATE TITLE
01AUG2021:00:00:00 01OCT2021:00:00:00 2021 Batch 1
01JUL2021:00:00:00 01OCT2021:00:00:00 2021 Batch 2
01JUN2021:00:00:00 01OCT2021:00:00:00 2021 Batch 3
Check out my Jedi SAS Tricks for SAS Users
ballardw
Super User

@temsandroses wrote:

I am trying to pull data from oracle based on the 3 columns from the input file:

 

start_date| end_date | title

01aug2021 | 01oct2021| 2021 Batch 1

01jul2021 | 01oct2021| 2021 Batch 2

01jun2021 | 01oct2021| 2021 Batch 3

 

For each title I want to obtain data for each day only within the start and end date.

 

Is there a way to do so?


And what does "data for each day only within the start and end date" look like?

I'm not sure the "example" shown is the input or the output. If the input, what is the output supposed to look like?

If that is the output then what does the input look like?

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 917 views
  • 0 likes
  • 3 in conversation