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

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.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@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.

View solution in original post

1 REPLY 1
ballardw
Super User

@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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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