BookmarkSubscribeRSS Feed
ChristyN
Fluorite | Level 6

Hi there, looking for some help. Here is what I am trying to do and the datasetep I am using. It works but takes a really long time to run given the number of obs in my data. Anyone know of an alternative program to get what I want?

 

Dataset 1                                                          Dataset2

ID           Legal     Charge                                Charge                 Status

1             1             A                                           A                            Rem

1             1             B                                           A                            Sent

1             2             A                                           A                            Time     

2             1             C                                           B                            Sent

2             2             C                                           B                            TIC

                                                                           C                            Rem

                                                                           C                            Fed

  

Resulting Dataset

 

 ID          Legal     Charge                 Status

1             1             A                            Rem

1             1             A                            Sent

1             1             A                            Time

1             1             B                            Sent

1             1             B                            TIC

1             2             A                            Rem

1             2             A                            Sent

1             2             A                            Time

2             1             C                            Rem

2             1             C                            Fed

2             2             C                            Rem

2             2             C                            Fed

 

data Result;
set Dataset1;
drop _:; 
match = 0; 
do i=1 to xnobs;
set Dataset2 (rename = (charge=_charge)) nobs=xnobs point=i;
if charge = _charge then do;
match = 1; 
output;
end;
end;
run;

2 REPLIES 2
ballardw
Super User

Something like this perhaps:

proc sql;
   create table want as
   select dataset1.*, dataset2.status
   from dataset1 left join dataset2 
        on dataset1.charge = dataset2.charge;
quit;
ChristyN
Fluorite | Level 6

Thanks I'll try it!

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
  • 2 replies
  • 832 views
  • 0 likes
  • 2 in conversation