BookmarkSubscribeRSS Feed
manojsanthi
Calcite | Level 5

Hello,

I am new to SAS and to SAS Data Step. I want to know how I can update a Variable V1 in a Data Set A with the Value "Yes" whenever there is a match with Data Set B having a common Variable V2 between the 2 data sets?

4 REPLIES 4
Reeza
Super User
Depends on your data structure, but you can try a MERGE or UPDATE statement or MODIFY as starters.
manojsanthi
Calcite | Level 5

I read about Merge and Update, but I don't see how it can benefit my specific query as I am looking to enter a Constant String value in a Variable when ever there is a match in Values between 2 tables.

Reeza
Super User
Show an example of why you think it won't work.
Astounding
PROC Star

You're looking in the right direction.  You need to add to what you have seen so far by adding IN= variables when you MERGE.  For example:

 

data want;
   merge a (in=from_a) b (in=from_b);
   by V2;
   if from_a;
   if from_b then v1='Yes';
run;

This example assumes that both data sets are already in sortedf order by V2.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 931 views
  • 0 likes
  • 3 in conversation