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.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 1252 views
  • 0 likes
  • 2 in conversation