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

I have a dataset A that has 96 hourly observations (var_A). I also have a dataset B that has 24 average hourly observations (var_B).

 

I want to combine the datasets A & B  to make dataset C (attached).

 

How do I repeat the datalines of var_B from dataset B so that dataset C shows the same 24 average hourly values over and over until the end of the dataset A?

data c;
	set c;
	input avg_delivered_kw @@;
	datalines;
1.2075434357
1.1069760113
1.0151325226
0.9682368384
1.0312725859
1.0515738245
0.8532573946
0.6135882055
0.4793938309
0.4483874046
0.5043064344
0.5824541904
0.7168952859
0.9070687706
1.1672568734
1.6091569573
2.1673370093
2.5960530086
2.5846035421
2.4253723858
2.2624625265
1.9173588172
1.5982197997
1.3700097842
;
run;

  My excel file attachment may explain better the desired end result for dataset C. 

 

Dataset A:

DateHourvar_A
6/1/20181001
6/1/20182002
6/1/20183003
6/1/20184004
6/1/20185005
6/1/20186006
6/1/20187007
6/1/20188008
6/1/20189009
6/1/2018100010
6/1/2018110011
6/1/2018120012
6/1/2018130013
6/1/2018140014
6/1/2018150015
6/1/2018160016
6/1/2018170017
6/1/2018180018
6/1/2018190019
6/1/2018200020
6/1/2018210021
6/1/2018220022
6/1/2018230023
6/1/2018240024
6/4/201810025
6/4/201820026
6/4/201830027
6/4/201840028
6/4/201850029
6/4/201860030
6/4/201870031
6/4/201880032
6/4/201890033
6/4/2018100034
6/4/2018110035
6/4/2018120036
6/4/2018130037
6/4/2018140038
6/4/2018150039
6/4/2018160040
6/4/2018170041
6/4/2018180042
6/4/2018190043
6/4/2018200044
6/4/2018210045
6/4/2018220046
6/4/2018230047
6/4/2018240048
6/5/201810049
6/5/201820050
6/5/201830051
6/5/201840052
6/5/201850053
6/5/201860054
6/5/201870055
6/5/201880056
6/5/201890057
6/5/2018100058
6/5/2018110059
6/5/2018120060
6/5/2018130061
6/5/2018140062
6/5/2018150063
6/5/2018160064
6/5/2018170065
6/5/2018180066
6/5/2018190067
6/5/2018200068
6/5/2018210069
6/5/2018220070
6/5/2018230071
6/5/2018240072
6/6/201810073
6/6/201820074
6/6/201830075
6/6/201840076
6/6/201850077
6/6/201860078
6/6/201870079
6/6/201880080
6/6/201890081
6/6/2018100082
6/6/2018110083
6/6/2018120084
6/6/2018130085
6/6/2018140086
6/6/2018150087
6/6/2018160088
6/6/2018170089
6/6/2018180090
6/6/2018190091
6/6/2018200092
6/6/2018210093
6/6/2018220094
6/6/2018230095
6/6/2018240096

 

Dataset B:

Hourvar_B
1002.1
2003.1
3004.1
4005.1
5006.1
6007.1
7008.1
8009.1
90010.1
100011.1
110012.1
120013.1
130014.1
140015.1
150016.1
160017.1
170018.1
180019.1
190020.1
200021.1
210022.1
220023.1
230024.1
240025.1

 

Dataset C (goal dataset):

DateHourvar_Avar_B
6/1/201810012.1
6/1/201820023.1
6/1/201830034.1
6/1/201840045.1
6/1/201850056.1
6/1/201860067.1
6/1/201870078.1
6/1/201880089.1
6/1/2018900910.1
6/1/201810001011.1
6/1/201811001112.1
6/1/201812001213.1
6/1/201813001314.1
6/1/201814001415.1
6/1/201815001516.1
6/1/201816001617.1
6/1/201817001718.1
6/1/201818001819.1
6/1/201819001920.1
6/1/201820002021.1
6/1/201821002122.1
6/1/201822002223.1
6/1/201823002324.1
6/1/201824002425.1
6/4/2018100252.1
6/4/2018200263.1
6/4/2018300274.1
6/4/2018400285.1
6/4/2018500296.1
6/4/2018600307.1
6/4/2018700318.1
6/4/2018800329.1
6/4/20189003310.1
6/4/201810003411.1
6/4/201811003512.1
6/4/201812003613.1
6/4/201813003714.1
6/4/201814003815.1
6/4/201815003916.1
6/4/201816004017.1
6/4/201817004118.1
6/4/201818004219.1
6/4/201819004320.1
6/4/201820004421.1
6/4/201821004522.1
6/4/201822004623.1
6/4/201823004724.1
6/4/201824004825.1
6/5/2018100492.1
6/5/2018200503.1
6/5/2018300514.1
6/5/2018400525.1
6/5/2018500536.1
6/5/2018600547.1
6/5/2018700558.1
6/5/2018800569.1
6/5/20189005710.1
6/5/201810005811.1
6/5/201811005912.1
6/5/201812006013.1
6/5/201813006114.1
6/5/201814006215.1
6/5/201815006316.1
6/5/201816006417.1
6/5/201817006518.1
6/5/201818006619.1
6/5/201819006720.1
6/5/201820006821.1
6/5/201821006922.1
6/5/201822007023.1
6/5/201823007124.1
6/5/201824007225.1
6/6/2018100732.1
6/6/2018200743.1
6/6/2018300754.1
6/6/2018400765.1
6/6/2018500776.1
6/6/2018600787.1
6/6/2018700798.1
6/6/2018800809.1
6/6/20189008110.1
6/6/201810008211.1
6/6/201811008312.1
6/6/201812008413.1
6/6/201813008514.1
6/6/201814008615.1
6/6/201815008716.1
6/6/201816008817.1
6/6/201817008918.1
6/6/201818009019.1
6/6/201819009120.1
6/6/201820009221.1
6/6/201821009322.1
6/6/201822009423.1
6/6/201823009524.1
6/6/201824009625.1
1 ACCEPTED SOLUTION

Accepted Solutions
KALLEN
Obsidian | Level 7

This was my solution:

proc sort data=dataset_a;
	by Hour;
run;

data dataset_c;
	merge dataset_a dataset_b;
	by hour;
run;

proc sort data=dataset_c;
	by Date;
run;

View solution in original post

2 REPLIES 2
Reeza
Super User
Add an hour value into the data set so you can merge by group AND hour and it will replicate by default. This assumes you have a variable that identifies different groups already.

Sorry can't download or view attachments due to security restrictions so no idea what's in that file.
KALLEN
Obsidian | Level 7

This was my solution:

proc sort data=dataset_a;
	by Hour;
run;

data dataset_c;
	merge dataset_a dataset_b;
	by hour;
run;

proc sort data=dataset_c;
	by Date;
run;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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
  • 844 views
  • 1 like
  • 2 in conversation