<?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 New variable taking on existing variable values in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/New-variable-taking-on-existing-variable-values/m-p/913636#M40908</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to generate a variable (businessnm) that takes on the values of an existing raw variable (Name) when another variable (opartytyp) has a value of "Business". Prior to this attempt, I rename a raw data variable (Type_of_Plaintiff_Resondent) to be "opartytyp".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I do this, I get the following warning: "WARNING: Variable opartytyp already exists on file WORK.CASES_1." And the "businessnm" variable is not generated. Thoughts?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data cases_1;
  set cases;

  	/*Rename the variables that don't need any editing*/
	rename Type_of_Plaintiff_Respondent = opartytyp;

        /*Generate a new variable (businessnm) that takes on values of the raw "Name" variable when the opartytyp variable has a value of "Business" */
	if opartytyp="Business" then businessnm=Name;
run;&lt;/PRE&gt;</description>
    <pubDate>Tue, 30 Jan 2024 17:55:02 GMT</pubDate>
    <dc:creator>raivester</dc:creator>
    <dc:date>2024-01-30T17:55:02Z</dc:date>
    <item>
      <title>New variable taking on existing variable values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-variable-taking-on-existing-variable-values/m-p/913636#M40908</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to generate a variable (businessnm) that takes on the values of an existing raw variable (Name) when another variable (opartytyp) has a value of "Business". Prior to this attempt, I rename a raw data variable (Type_of_Plaintiff_Resondent) to be "opartytyp".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I do this, I get the following warning: "WARNING: Variable opartytyp already exists on file WORK.CASES_1." And the "businessnm" variable is not generated. Thoughts?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data cases_1;
  set cases;

  	/*Rename the variables that don't need any editing*/
	rename Type_of_Plaintiff_Respondent = opartytyp;

        /*Generate a new variable (businessnm) that takes on values of the raw "Name" variable when the opartytyp variable has a value of "Business" */
	if opartytyp="Business" then businessnm=Name;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jan 2024 17:55:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-variable-taking-on-existing-variable-values/m-p/913636#M40908</guid>
      <dc:creator>raivester</dc:creator>
      <dc:date>2024-01-30T17:55:02Z</dc:date>
    </item>
    <item>
      <title>Re: New variable taking on existing variable values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-variable-taking-on-existing-variable-values/m-p/913645#M40909</link>
      <description>&lt;P&gt;Your description of the problem in words does not include a renaming step, so don't put one in. Your description of the problem in words does include an IF condition, you do need that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Renaming not needed here. Take it out of your data step and run it again.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 18:13:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-variable-taking-on-existing-variable-values/m-p/913645#M40909</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-01-30T18:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: New variable taking on existing variable values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-variable-taking-on-existing-variable-values/m-p/913646#M40910</link>
      <description>&lt;P&gt;Thank you. That worked. I moved the rename statement below the section where I generate the businessnm variable. However, I am wondering why SAS doesn't let me do the rename first . . . .&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 18:32:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-variable-taking-on-existing-variable-values/m-p/913646#M40910</guid>
      <dc:creator>raivester</dc:creator>
      <dc:date>2024-01-30T18:32:56Z</dc:date>
    </item>
    <item>
      <title>Re: New variable taking on existing variable values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-variable-taking-on-existing-variable-values/m-p/913647#M40911</link>
      <description>&lt;P&gt;What is the need to rename here? This isn't obvious from your word description of the problem.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 18:37:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-variable-taking-on-existing-variable-values/m-p/913647#M40911</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-01-30T18:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: New variable taking on existing variable values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-variable-taking-on-existing-variable-values/m-p/913649#M40912</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/326526"&gt;@raivester&lt;/a&gt;,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/326526"&gt;@raivester&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;(...)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Prior to this attempt, I rename a raw data variable ...&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you want the renaming&amp;nbsp;to happen &lt;EM&gt;prior&lt;/EM&gt; to the IF-THEN statement referring to the renamed variable (as it should), you must apply a RENAME= &lt;EM&gt;dataset option&lt;/EM&gt; to the dataset read by the SET statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set cases(rename=(Type_of_Plaintiff_Respondent = opartytyp));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The effect of the (declarative) RENAME &lt;EM&gt;statement&lt;/EM&gt;&amp;nbsp;comes too late: An uninitialized* variable &lt;FONT face="courier new,courier"&gt;opartytyp&lt;/FONT&gt; is used in the IF-THEN statement and eventually replaced by the renamed variable&amp;nbsp;&lt;FONT face="courier new,courier"&gt;Type_of_Plaintiff_Respondent&lt;/FONT&gt;&amp;nbsp;and the name conflict causes the warning "&lt;FONT face="courier new,courier"&gt;Variable opartytyp already exists&lt;/FONT&gt; ...".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*assuming that &lt;FONT face="courier new,courier"&gt;opartytyp&lt;/FONT&gt; is not contained in dataset CASES -- otherwise it is the variable read from CASES, but then you cannot rename the other variable with the dataset option to this same name&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2024 18:59:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-variable-taking-on-existing-variable-values/m-p/913649#M40912</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-01-30T18:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: New variable taking on existing variable values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-variable-taking-on-existing-variable-values/m-p/913656#M40913</link>
      <description>We need to have standardized names across multiple data sets; therefore, the final variable names of this data set must follow the established convention.</description>
      <pubDate>Tue, 30 Jan 2024 19:20:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-variable-taking-on-existing-variable-values/m-p/913656#M40913</guid>
      <dc:creator>raivester</dc:creator>
      <dc:date>2024-01-30T19:20:38Z</dc:date>
    </item>
    <item>
      <title>Re: New variable taking on existing variable values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-variable-taking-on-existing-variable-values/m-p/913657#M40914</link>
      <description>Ahh! Thank you!</description>
      <pubDate>Tue, 30 Jan 2024 19:21:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-variable-taking-on-existing-variable-values/m-p/913657#M40914</guid>
      <dc:creator>raivester</dc:creator>
      <dc:date>2024-01-30T19:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: New variable taking on existing variable values</title>
      <link>https://communities.sas.com/t5/New-SAS-User/New-variable-taking-on-existing-variable-values/m-p/913668#M40915</link>
      <description>&lt;P&gt;Don't put RENAME statements in the middle of a data step.&amp;nbsp; That is just confusing.&amp;nbsp; Put them as the LAST statement since they impact the name that is written to the output dataset(s).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cases_1;
  set cases;
*-----------------------------------------------------------------------------;
* Generate a new variable (businessnm) that takes on values of the NAME ;
* variable when the opartytyp variable has a value of "Business" ;
*-----------------------------------------------------------------------------; 
  if Type_of_Plaintiff_Respondent="Business" then businessnm=Name;

* Rename the variables that do not need any editing ;
  rename Type_of_Plaintiff_Respondent = opartytyp;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or use the RENAME= dataset option so the name is changed BEFORE it comes into the data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;resetline;
data cases_1;
  set cases(rename=(Type_of_Plaintiff_Respondent = opartytyp));

*-----------------------------------------------------------------------------;
* Generate a new variable (businessnm) that takes on values of the NAME ;
* variable when the opartytyp variable has a value of "Business" ;
*-----------------------------------------------------------------------------; 
  if opartytyp="Business" then businessnm=Name;

run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Jan 2024 20:25:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/New-variable-taking-on-existing-variable-values/m-p/913668#M40915</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-01-30T20:25:50Z</dc:date>
    </item>
  </channel>
</rss>

