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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 1006 views
  • 0 likes
  • 2 in conversation