<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: the impact of putting rename function in different location within data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/the-impact-of-putting-rename-function-in-different-location/m-p/907462#M358201</link>
    <description>&lt;P&gt;Why are you confused?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you tell us which statement is specifying the INPUT to the data step?&lt;/P&gt;
&lt;P&gt;Can you tell us which statement is specify where the OUTPUT of the data step will be saved?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you can see that then for each step explain&lt;/P&gt;
&lt;P&gt;1) What variables names will come into the data step.&lt;/P&gt;
&lt;P&gt;2) What variable names will exist while the data step is running.&lt;/P&gt;
&lt;P&gt;3) What variable names will be written to the output dataset.&lt;/P&gt;</description>
    <pubDate>Tue, 12 Dec 2023 04:13:30 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-12-12T04:13:30Z</dc:date>
    <item>
      <title>the impact of putting rename function in different location within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/the-impact-of-putting-rename-function-in-different-location/m-p/907454#M358196</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following questions confused me a lot, I would like to understand the following codes, specifically, how they impact the results when I put the rename function on the different locations within the data step.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;first piece:&lt;/P&gt;&lt;P&gt;Data new_student1;&lt;/P&gt;&lt;P&gt;set student;&lt;/P&gt;&lt;P&gt;rename gender = sex;&lt;/P&gt;&lt;P&gt;if name = 'jack' then gender = 'm';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;second piece:&lt;/P&gt;&lt;P&gt;Data new_student2;&lt;/P&gt;&lt;P&gt;set student (rename = (gender = sex));&lt;/P&gt;&lt;P&gt;if name = 'jack' then sex = 'm';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;third piece:&lt;/P&gt;&lt;P&gt;Data new_student3&amp;nbsp; (rename = (gender = sex));&lt;/P&gt;&lt;P&gt;set student;&lt;/P&gt;&lt;P&gt;if name = 'jack' then gender = 'm';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone explain in detail how the code runs in sequence and what the results for each step are?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Much appreciated!&lt;/P&gt;&lt;P&gt;Sam&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2023 02:23:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/the-impact-of-putting-rename-function-in-different-location/m-p/907454#M358196</guid>
      <dc:creator>ForrestYao</dc:creator>
      <dc:date>2023-12-12T02:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: the impact of putting rename function in different location within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/the-impact-of-putting-rename-function-in-different-location/m-p/907462#M358201</link>
      <description>&lt;P&gt;Why are you confused?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you tell us which statement is specifying the INPUT to the data step?&lt;/P&gt;
&lt;P&gt;Can you tell us which statement is specify where the OUTPUT of the data step will be saved?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you can see that then for each step explain&lt;/P&gt;
&lt;P&gt;1) What variables names will come into the data step.&lt;/P&gt;
&lt;P&gt;2) What variable names will exist while the data step is running.&lt;/P&gt;
&lt;P&gt;3) What variable names will be written to the output dataset.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2023 04:13:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/the-impact-of-putting-rename-function-in-different-location/m-p/907462#M358201</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-12T04:13:30Z</dc:date>
    </item>
    <item>
      <title>Re: the impact of putting rename function in different location within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/the-impact-of-putting-rename-function-in-different-location/m-p/907533#M358234</link>
      <description>&lt;P&gt;The first data step and the second do the same thing, but in different ways. When RENAME is used as a statement as in the first data step, the variable is renamed on the output dataset, but not in the statements in the data step. So, in data step 1, the gender variable is modified, and then renamed to "sex" on the output dataset. In the second data step, the gender variable is renamed when the data is read, so it is called "sex" in the data step, and in the output data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;RENAME used as a statement is non-executable, meaning that it does not matter where you put it in the code (unless you put it before the SET statement, in which case the RENAME statement will be the definition of the GENDER variable, meaning it will be numeric, and the code will generate an error).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the third data step, the gender variable is renamed when the data is read, and then a new variable named "gender" is created. The new variable is only assigned a value when name='jack', and the sex variable (which was the original "gender" variable) is not modified.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope that answers your questions.&lt;/P&gt;</description>
      <pubDate>Tue, 12 Dec 2023 13:41:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/the-impact-of-putting-rename-function-in-different-location/m-p/907533#M358234</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-12-12T13:41:28Z</dc:date>
    </item>
    <item>
      <title>Re: the impact of putting rename function in different location within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/the-impact-of-putting-rename-function-in-different-location/m-p/907691#M358301</link>
      <description>thanks, may i ask one more question, i guess the real confusing part for me is when the if statement becomes effective? For example, the first query, rename happens after new_student1 is created, and it will not change table student_score, but when the if statement will happen? will it happen before or afte r the rename statement? because in new_student1, the gender attribute has already been renamed to sex, then why the if statement still says gender = M? much appreciated your reply!</description>
      <pubDate>Wed, 13 Dec 2023 01:34:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/the-impact-of-putting-rename-function-in-different-location/m-p/907691#M358301</guid>
      <dc:creator>ForrestYao</dc:creator>
      <dc:date>2023-12-13T01:34:33Z</dc:date>
    </item>
    <item>
      <title>Re: the impact of putting rename function in different location within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/the-impact-of-putting-rename-function-in-different-location/m-p/907692#M358302</link>
      <description>i meant student instead of student_score, just FYI</description>
      <pubDate>Wed, 13 Dec 2023 01:35:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/the-impact-of-putting-rename-function-in-different-location/m-p/907692#M358302</guid>
      <dc:creator>ForrestYao</dc:creator>
      <dc:date>2023-12-13T01:35:38Z</dc:date>
    </item>
    <item>
      <title>Re: the impact of putting rename function in different location within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/the-impact-of-putting-rename-function-in-different-location/m-p/907696#M358306</link>
      <description>&lt;P&gt;The IF statement is a EXECUTABLE statement.&amp;nbsp; Just like an assignment statement.&lt;/P&gt;
&lt;P&gt;It executes for every iteration of the data step when the program flow gets to that part of the program.&amp;nbsp; &amp;nbsp;So in your simple data steps the IF statement will execute once for every observation read in by the SET statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The RENAME statement is NOT an EXECUTABLE statement. It just helps the compiler set up the data step. So it let's SAS know that when it is ready to setup the output dataset(s) that the name in the new dataset should be the new name, not the name that the variable was referenced by while the data step was executing.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Dec 2023 03:28:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/the-impact-of-putting-rename-function-in-different-location/m-p/907696#M358306</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-12-13T03:28:46Z</dc:date>
    </item>
  </channel>
</rss>

