BookmarkSubscribeRSS Feed
ealderm2
Calcite | Level 5

I'm trying to merge 2 data sets. One has many rows with a date and the other has 3 rows and a data range with the aplicable value that i need to be picked up.

I need to show the correct value for each row in a by picking up the correct value within the date range specified.

I have tried the following -

proc sql;

create table work.EDW_ALL as
select *
from EDW_PLUS_CPC a
left join DCA_PERCENT b
ON a.DEALER_CODE=b.dealer_code
and A.CPC=B.CPC
AND  A.DLR_IP=B.DLR_IP
and PURCHASE_DATE >= CPA_START_DT
AND PURCHASE_DATE <= CPA_EXP_DT
;
QUIT;

This gives me all the 225 rows I need but only gives me the merged value when the date falls into the first range on the b dataset,

and

data work.EDW_ALL;

merge      EDW_PLUS_CPC (in=a)

  DCA_PERCENT (in=b);

by DEALER_CODE CPC DLR_IP;

if (PURCHASE_DATE >= CPA_START_DT

AND PURCHASE_DATE <= CPA_EXP_DT);

if a then

  output work.EDW_ALL;

run

This gives me just 10 rows where the date falls into the first range on the b dataset.

It would appear that the first row is being picked up rather than picking up the correct value for each date/row.

Any thoughts would be gratefully appreciated.

Thanks


2 REPLIES 2
Steelers_In_DC
Barite | Level 11

Do you get the desired results using a where clause in the second example?  Depending on where the data comes from you can do this:

dca_percent(in=b where=(PURCHASE_DATE >= CPA_START_DT AND PURCHASE_DATE <= CPA_EXP_DT));

JayCorbett
Calcite | Level 5

Could you post some sample data? Is the "Applicable Value" variable the same or different in the two data sets?

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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