Hi all,
When calculating one variable, I accidentally calculate the same named variable by two different methods, they all in the same dataset:
x= y-z;
x=m-n;
I am wondering whether the previous x will be replaced totally by the later x? Or just be replaced partly? Is there any exception that the later x just replace the former x partly?
Thank you.
@ResoluteCarbon wrote:
Hi all,
When calculating one variable, I accidentally calculate the same named variable by two different methods, they all in the same dataset:
x= y-z; x=m-n;
I am wondering whether the previous x will be replaced totally by the later x? Or just be replaced partly? Is there any exception that the later x just replace the former x partly?
Thank you.
Yep.
When executing code in a data step it evaluates things from the "top" of the data step code to the bottom.
So if you assign a different value on a line below the first assignment the bottom one is the result.
The "exceptions" would all come if one or both of the assignments are conditional.
If sex='F' then x = (some calculation based on the sex);
else if sex='M' then x = (different calculation based on sex);
There is no "partly" unless you mean a character value where you assign different bits and pieces, which is possible but you would need to do the coding to implement such. With numeric values, not going to happen.
@ResoluteCarbon wrote:
Hi all,
When calculating one variable, I accidentally calculate the same named variable by two different methods, they all in the same dataset:
x= y-z; x=m-n;
I am wondering whether the previous x will be replaced totally by the later x? Or just be replaced partly? Is there any exception that the later x just replace the former x partly?
Thank you.
Yep.
When executing code in a data step it evaluates things from the "top" of the data step code to the bottom.
So if you assign a different value on a line below the first assignment the bottom one is the result.
The "exceptions" would all come if one or both of the assignments are conditional.
If sex='F' then x = (some calculation based on the sex);
else if sex='M' then x = (different calculation based on sex);
There is no "partly" unless you mean a character value where you assign different bits and pieces, which is possible but you would need to do the coding to implement such. With numeric values, not going to happen.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.