BookmarkSubscribeRSS Feed
bqk
Calcite | Level 5 bqk
Calcite | Level 5
i have 2 dataset data1 data2 as following

data data1;
input date : yymmdd10. best_offer ;
format date yymmdd10.;
datalines;
2006/2/24 1.6
2006/2/24 0.3
2006/2/24 4.3
2006/2/24 1.4
2006/2/24 0.85
2006/3/20 2.5
2006/3/20 2.6
2006/3/20 1.57
2006/3/20 1.45
2006/4/19 1.78
2006/4/19 1.45
;
run;

data data2;
input futures_date : yymmdd10. futures_price ;
format futures_date yymmdd10.;
datalines;
2004/5/12 18.2
2004/5/13 19.58
2004/5/14 19.67
2004/5/17 20.21
2004/5/18 20.07
2004/5/19 19.17
2006/2/11 19.34
2006/3/15 19.17
2006/4/20 18.77
2006/5/10 17.5
2006/6/15 17.61
2006/7/20 17.35
;
run;

data data2;
input futures_date : yymmdd10. futures_price ;
format futures_date yymmdd10.;
datalines;
2004/5/12 18.2
2004/5/13 19.58
2004/5/14 19.67
2004/5/17 20.21
2004/5/18 20.07
2004/5/19 19.17
2006/2/11 19.34
2006/3/15 19.17
2006/4/20 18.77
2006/5/10 17.5
2006/6/15 17.61
2006/7/20 17.35
;
run;

i want to set the 2 dataset in the above merge as the data3

data data3;
input date : yymmdd10. best_offer futures_date : yymmdd10. futures_price ;
format date : yymmdd10. futures_date yymmdd10.;
datalines;
2006/02/24 1.6 2006/02/11 19.34
2006/02/24 0.3 2006/02/11 19.34
2006/02/24 4.3 2006/02/11 19.34
2006/02/24 1.4 2006/02/11 19.34
2006/02/24 0.85 2006/02/11 19.34
2006/03/20 2.5 2006/03/15 19.17
2006/03/20 2.6 2006/03/15 19.17
2006/03/20 1.57 2006/03/15 19.17
2006/03/20 1.45 2006/03/15 19.17
2006/04/19 1.78 2006/04/20 18.77
2006/04/19 1.45 2006/04/20 18.77
;
run;

the question is i have to merge them but they have the same year and month but the date is different.

i want to combine them with the same year and month

please help me , thx
1 REPLY 1
Ksharp
Super User
OK.That is easy.
[pre]
data data1;
input date : yymmdd10. best_offer ;
format date yymmdd10.;
flag=put(date,monyy.);
datalines;
2006/2/24 1.6
2006/2/24 0.3
2006/2/24 4.3
2006/2/24 1.4
2006/2/24 0.85
2006/3/20 2.5
2006/3/20 2.6
2006/3/20 1.57
2006/3/20 1.45
2006/4/19 1.78
2006/4/19 1.45
;
run;

data data2;
input futures_date : yymmdd10. futures_price ;
format futures_date yymmdd10.;
flag=put(futures_date,monyy.);
datalines;
2004/5/12 18.2
2004/5/13 19.58
2004/5/14 19.67
2004/5/17 20.21
2004/5/18 20.07
2004/5/19 19.17
2006/2/11 19.34
2006/3/15 19.17
2006/4/20 18.77
2006/5/10 17.5
2006/6/15 17.61
2006/7/20 17.35
;
run;
proc sort data=data1;
by flag;
run;
proc sort data=data2;
by flag;
run;
data want;
merge data1 data2;
by flag;
drop flag;
run;
proc sort data=want;
by date;
run;
[/pre]


Ksharp

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 1 reply
  • 721 views
  • 0 likes
  • 2 in conversation