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.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 394 views
  • 1 like
  • 2 in conversation