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

Hi

I have trying to merge two data sets as indicated below. For the variable I am looking for merge (CohortYearTotalAge), the merge is merging the value for the first record in the sort, but not the remaining. Anyone see anything by any chance? I tried it several ways.

Paul

1st data set:

proc sort data=surrenderTprCount2;

by County Year AgeRange Filing;

run;

2nd data set:

proc sort data=s1Permanency1c;

by County Year AgeRange Filing;

run;

Merge:

data s1Permanency2;

merge s1Permanency1c surrenderTprCount2;

by County Year AgeRange Filing;

run;

Part of the result:

CountyYearAgeRangeFilingExitExitMonthCategoryCohortYearTotalCohortYearTotalAgeDistributiveNumberCumulativeNumber
1 - New York State20061 - 0 to 32 - AS Filed, No TPRAll01218815700
1 - New York State20061 - 0 to 32 - AS Filed, No TPRAll0.512188463211
1 - New York State20061 - 0 to 32 - AS Filed, No TPRAll112188463201
1 - New York State20061 - 0 to 32 - AS Filed, No TPRAll212188463201
1 - New York State20061 - 0 to 32 - AS Filed, No TPRAll312188463212
1 - New York State20061 - 0 to 32 - AS Filed, No TPRAll412188463235
1 - New York State20061 - 0 to 32 - AS Filed, No TPRAll512188463227
1 - New York State20061 - 0 to 32 - AS Filed, No TPRAll6121884632411
1 - New York State20061 - 0 to 32 - AS Filed, No TPRAll121218846321021
1 - New York State20061 - 0 to 32 - AS Filed, No TPRAll181218846322647
1 - New York State20061 - 0 to 32 - AS Filed, No TPRAll241218846322370
1 - New York State20061 - 0 to 32 - AS Filed, No TPRAll301218846322696
1 - New York State20061 - 0 to 32 - AS Filed, No TPRAll3612188463218114
1 - New York State20061 - 0 to 32 - AS Filed, No TPRAll4212188463215129
1 - New York State20061 - 0 to 32 - AS Filed, No TPRAll481218846328137
1 - New York State20061 - 0 to 32 - AS Filed, No TPRAll541218846325142
1 - New York State20061 - 0 to 32 - AS Filed, No TPRAll601218846324146
1 - New York State20061 - 0 to 32 - AS Filed, No TPRAll661218846321147
1 - New York State20061 - 0 to 32 - AS Filed, No TPRAll721218846324151
1 - New York State20061 - 0 to 32 - AS Filed, No TPRAll781218846321152
1 - New York State20061 - 0 to 32 - AS Filed, No TPRAll841218846320152
1 - New York State20061 - 0 to 32 - AS Filed, No TPRAll871218846321153
1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Most likely, the variable in question appears in both incoming data sets when it should only appear in one.  Drop it from one of the data sets.

View solution in original post

5 REPLIES 5
LinusH
Tourmaline | Level 20

Merging data sets without unique by variables (key) is risky business.

By looking at your result, my guess is that you have 22 rows from the first table, and two rows from the second.

What is the desired result?

Data never sleeps
Astounding
PROC Star

Most likely, the variable in question appears in both incoming data sets when it should only appear in one.  Drop it from one of the data sets.

Paul_NYS
Obsidian | Level 7

Hi Astounding

That was it. It was in both, so I had to do a two step merge to accommodate what I was doing.

Thanks a lot!

Paul

Astounding
PROC Star

Great!  Also note for future use, you can do this in one step along these lines:

data want;

merge have1 (drop=CohortYearTotalAge)

           have2;

by County Year AgeRange Filing;

run;


Paul_NYS
Obsidian | Level 7

Actually its not as much a technical aspect in needing the two steps. Its that dropping the column caused another issue in the merge.

Paul

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!

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
  • 5 replies
  • 1096 views
  • 0 likes
  • 3 in conversation