BookmarkSubscribeRSS Feed
Paul_NYS
Obsidian | Level 7

Hi

I am  trying to merge two data sets (something I have done 500 times). The field I am trying to add to the first from the second is not copying correctly in that the values are not matching correctly based on the 'by' variable. I have tried it several different ways and nothing seems to work. Anyone see anything? Its the AppearCount variable that I want to add and the values for it are not matching. Also the second data set (appearances2bt1) is actually a subset of the first.

Paul

proc sort data=appearances2b;
by docket_id;
run;


proc sort data=appearances2bt1;
by docket_id;
run;

data AppearanceAttendDen;
length EventType $ 50;
merge appearances2b (in=a) appearances2bt1 (keep=docket_id AppearCount);
if a;
by docket_id;


if event in ("AAD","AHR","ACT","AIQ","ANE","ANH","ACD","AHY","ASJ")
then EventType="Adjudication";

if event in ("DDD","DRR","DPP","DTP","DAJ","DSP","DDS","DOR",
"DWD") then EventType="Disposition";

if event in ("XCA","XRF","XRL","XGA","XAP","XRM","XOT") then EventType="Exit";

if event in ("PHR","PHC") then EventType="PermanencyHearing";

drop AGEOUT IY NYC FCOUNT OCOUNT SCOUNT TCOUNT PCOUNT HCOUNT
DURCAT_ADJUD_DISPO1 DURCAT_ADJUD1 DUR_PL1 DURCAT_PL1
PLACE_CAT1 TADJUD_FLAG CENSOR_TADJUD1 CENSOR_TADJUD1 DURCAT_TADJUD_TDISPO1 DURCAT_TADJUD_TDISPO1
durmod durmod_cat state link ageout count fcount_notpr place_end1 help durmoa durmoa_cat exit_pl1 stop_pl1
place1y;

run;

3 REPLIES 3
advoss
Quartz | Level 8

Yes, KurtBremser has made the correct observation.

Tell us what you are really trying to do, because the two tables are equivalent.  They have the same number of rows, and both have the variables docket_id and AppearCount with the exact same values...unless you are doing some additional processing on appearances2bt1 that you have not shown.

Assuming the latter, just drop AppearCount from appearances2b and you should get what you are expecting.

Rakeon
Quartz | Level 8

Hi,

I met your same problem with the merge statement,

In this post we talk about the merge statement in SAS:

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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