BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Alexxxxxxx
Pyrite | Level 9

Dear all,

 

how can I compare new_variable with the old_variable and show whether they have been changed( create a notification variable, say '1' if the new_variable is different from the old_variable, say '0' if both variables are the same.) The variables are different when they are the same word but different case.

 

for example, I expect to get the following result,

 

old_variable new_variable notification

apple Apple 1

juice juice 0

Original Original 0

mango nango 1

 

data have;
length 
old_variable $20 
new_variable $20 ;
input 
old_variable 
new_variable ;
cards;
apple Apple
juice juice 
Original Original 
mango nango 
;
run;

 

Could you please give me some suggestions about this?

thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

A simple comparison between the variables should do.

data have;
  length 
    old_variable $20 
    new_variable $20;
  input 
    old_variable 
    new_variable;

  change_flag= (old_variable ne new_variable);
  cards;
apple Apple
juice juice 
Original Original 
mango nango 
;
run;

What below line does:

change_flag= (old_variable ne new_variable);

old_variable ne new_variable -

Expression to compare the content in the two variables. The expression returns 1 (TRUE) if there is a difference and 0 (FALSE) if there is no difference

 

change_flag=

Variable to assign the result to from the result of the expression to the right of the equal sign.

 

View solution in original post

1 REPLY 1
Patrick
Opal | Level 21

A simple comparison between the variables should do.

data have;
  length 
    old_variable $20 
    new_variable $20;
  input 
    old_variable 
    new_variable;

  change_flag= (old_variable ne new_variable);
  cards;
apple Apple
juice juice 
Original Original 
mango nango 
;
run;

What below line does:

change_flag= (old_variable ne new_variable);

old_variable ne new_variable -

Expression to compare the content in the two variables. The expression returns 1 (TRUE) if there is a difference and 0 (FALSE) if there is no difference

 

change_flag=

Variable to assign the result to from the result of the expression to the right of the equal sign.

 

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
  • 767 views
  • 1 like
  • 2 in conversation