BookmarkSubscribeRSS Feed
martyvd
Fluorite | Level 6

I am translating a colleague's STATA code into SAS and am having trouble replicating the dataset. I think it is a merge issue.

 

His code: 

 

joinby var1 var2 var3 using dataset name unmatch(both)

 

My code:

DATA New; 
MERGE A3 (IN=A) D3 (IN=B);
BY var1 var2 var3;
IF A and B then link_status=1;
ELSE IF A and not B then link_status=2;
ELSE link_status=3;
RUN;

His code:

 

merge m:1 var1 using "filename"

 

My code:

 

data new_; 

merge new (in=A) externaldata (in=B);
by var1;
IF A and B then _merge=1;
ELSE IF A and not B then _merge=2;
ELSE _merge=3;
run;

 

 

Thanks.

 

 

 

1 REPLY 1
ballardw
Super User

Example input data and expected results would help. As it is we can not tell what is missing or added.

 

Provide just enough records and variables in the two sets being merged to show the issues and what the result should be for the example input data sets.

 

I don't speak STATA so can't work from the example code but have a pretty fair understanding of how to manipulate data in SAS.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1 reply
  • 870 views
  • 0 likes
  • 2 in conversation