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
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.
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.
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!
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.
Ready to level-up your skills? Choose your own adventure.