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

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.

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