Sunday 13 January 2013

Interchange values of two variables in SAS

Interchanging values of two variables is a very easy task if you introduce new variable. But if you are asked to interchange values of two variables in SAS without using third variable then you may need to think a little more.

It is quiet  simple. Following is the required code.


Data interchange;
x=10;
y=5;
output;
x=x+y;
y=x-y;
x=x-y;
output;
run;

Proc print data=interchange;
run;


This logic will help you writing simillar code in any other language.