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

Hi all,

I'm currently attempting to merge two databases, one has date level data, the other has month level data and I need the month level data to be repeated for all the days in that month for the first dataset.

for example:

dataset1

ID     Date

1     1/1/01

1     1/2/01

1     1/3/01

1     1/4/01

1      1/5/01

1     1/6/01

dataset2

ID     Date(month level)     Values

1          1/01                         5

Final dataset

ID     Date          Values

1     1/1/01               5

1     1/2/01               5

1     1/3/01               5

1     1/4/01               5

1     1/5/01               5

1     1/6/01               5

This is the code I've tried (ignore the date format as I'm using a diff format in my actual data) but this results in only the first day of each month assuming the value that I want applied to all days of the month.

PROC SQL;

  CREATE TABLE Finaldata AS

    SELECT A.ID,

      A.date FORMAT=YYMMDD8. AS date, 

      B.Values

      FROM dataset1A LEFT JOIN dataset2 B

        ON (A.ID= B.ID) AND 

          (A.date = B.date)

          ORDER BY ID, date;

QUIT;

Thanks for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Instead of

     AND  

      (A.date = B.date)

try

where     (month(a.date)=month(b.date) and year(a.date)=year(b.date))

View solution in original post

3 REPLIES 3
ballardw
Super User

Instead of

     AND  

      (A.date = B.date)

try

where     (month(a.date)=month(b.date) and year(a.date)=year(b.date))

Ksharp
Super User

I would like to us groupformat option.

data want;

merge dataset1 dataset2;

by id date groupformat;

format date monyy5.;

run;

Ksharp

Haikuo
Onyx | Level 15

It has been a very long time before I saw 'groupformat' in action! Seems more efficient comparing to sql if running on SAS side.

Haikuo

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 878 views
  • 3 likes
  • 4 in conversation