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

I am looking to merge on two variables, rather than just one. I want to match on both and ID number and a Date.

 

Thanks

 

 

data Final;
	merge Gts_7 (in=in1) 
		  Merged5;
	by ID Date;
	if in1;
	run;
1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

You have to sort your data first.

 

proc sort data=Merged5;
   by ID Date;
run;

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

What problems are you having?

--
Paige Miller
NickA1
Calcite | Level 5
ERROR: BY variables are not properly sorted on data set WORK.MERGED5.
in1=0 Date=. Govt_Yield=. GT=30 Cusip=915217WX7 Yield=. FIRST.GT=0 LAST.GT=0 FIRST.Date=0
LAST.Date=0 _ERROR_=1 _N_=42
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 6 observations read from the data set WORK.GTS_7.
NOTE: There were 38 observations read from the data set WORK.MERGED5.
WARNING: The data set WORK.FINAL may be incomplete. When this step was stopped there were 5
observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.04 seconds
PaigeMiller
Diamond | Level 26

@NickA1 wrote:
ERROR: BY variables are not properly sorted on data set WORK.MERGED5.
in1=0 Date=. Govt_Yield=. GT=30 Cusip=915217WX7 Yield=. FIRST.GT=0 LAST.GT=0 FIRST.Date=0
LAST.Date=0 _ERROR_=1 _N_=42
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 6 observations read from the data set WORK.GTS_7.
NOTE: There were 38 observations read from the data set WORK.MERGED5.
WARNING: The data set WORK.FINAL may be incomplete. When this step was stopped there were 5
observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.04 seconds

Seems like the error message (which I have highlighted in red) is relatively clear. 

--
Paige Miller
NickA1
Calcite | Level 5
proc sort data=Gts_7; by Date; run;
proc sort data=Merged5; by Date; run;

They were already sorted prior to that first code being run. Thanks.
PeterClemmensen
Tourmaline | Level 20

You have to sort your data first.

 

proc sort data=Merged5;
   by ID Date;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1279 views
  • 0 likes
  • 3 in conversation