<?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: Variable dropping from data set after calculation in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Variable-dropping-from-data-set-after-calculation/m-p/501600#M543</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/238261"&gt;@Hazelc&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I'm a beginner so please be kind! I need some help with the SAS code below, I am using two&amp;nbsp;variables called&amp;nbsp;calvingdate and dob to create a new variable called afc. However, I still&amp;nbsp;need calvingdate to remain in&amp;nbsp;my dataset (it disappears when I run the code below).&amp;nbsp;Is&amp;nbsp;there any command that will allow me to keep calvingdate while still creating the new variable afc? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=together2;
by techid;
run;

data together2;
merge together2 (in=a) first_weight (in=b);
by techid;
if a and b;
run;

data together2;
set together2;
afc=calvingdate-dob;
run;

&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!:)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Is the VARIABLE gone or are the values missing? And which data set(s)&amp;nbsp;contain the variables calvingdate and dob?&lt;/P&gt;
&lt;P&gt;IF first_weight has a missing value for calvingdate (or any other variable common with together2) then the value from first_weight replaced the value from together2. That is the way merge works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since your data step after the sort &lt;STRONG&gt;replaced&lt;/STRONG&gt; together2 with fewer records you will have to go back to a previous step and recreate the original together2.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Oct 2018 17:18:30 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-10-04T17:18:30Z</dc:date>
    <item>
      <title>Variable dropping from data set after calculation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Variable-dropping-from-data-set-after-calculation/m-p/501554#M532</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I'm a beginner so please be kind! I need some help with the SAS code below, I am using two&amp;nbsp;variables called&amp;nbsp;calvingdate and dob to create a new variable called afc. However, I still&amp;nbsp;need calvingdate to remain in&amp;nbsp;my dataset (it disappears when I run the code below).&amp;nbsp;Is&amp;nbsp;there any command that will allow me to keep calvingdate while still creating the new variable afc? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=together2;
by techid;
run;

data together2;
merge together2 (in=a) first_weight (in=b);
by techid;
if a and b;
run;

data together2;
set together2;
afc=calvingdate-dob;
run;

&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!:)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 16:10:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Variable-dropping-from-data-set-after-calculation/m-p/501554#M532</guid>
      <dc:creator>Hazelc</dc:creator>
      <dc:date>2018-10-04T16:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: Help</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Variable-dropping-from-data-set-after-calculation/m-p/501560#M533</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=together2;
by techid;
run;

data together3;
merge together2 (in=a) first_weight (in=b);
by techid;
if a and b;
run;

data together4;
set together3;
afc=calvingdate-dob;
run;

 &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There's nothing in your code to indicate why that variable may be dropped. I modified your code, you really shouldn't be using the same input and output data set names when you're coding, it makes it really hard to find errors. Try the code above and if it still doesn't work, please post the code and your log. There's likely something there that indicates why this is happening.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/238261"&gt;@Hazelc&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;Hi,&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;I'm a beginner so please be kind! I need some help with the SAS code below, I am using two&amp;nbsp;variables called&amp;nbsp;calvingdate and dob to create a new variable called afc. However, I still&amp;nbsp;need calvingdate to remain in&amp;nbsp;my dataset (it disappears when I run the code below).&amp;nbsp;Is&amp;nbsp;there any command that will allow me to keep calvingdate while still creating the new variable afc? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;sort&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=together2;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; techid;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;run&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; together2;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;merge&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; together2 (&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;in&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=a) first_weight (&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;in&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=b);&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; techid;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; a and b;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;run&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; together2;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; together2;afc=calvingdate-dob;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;run&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Thanks in advance!:)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 16:08:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Variable-dropping-from-data-set-after-calculation/m-p/501560#M533</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-04T16:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: Variable dropping from data set after calculation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Variable-dropping-from-data-set-after-calculation/m-p/501561#M534</link>
      <description>Please note that I edited your post slightly for formatting of the code and text and renamed it. Descriptive subject lines help other users find the posts when they have similar issues.</description>
      <pubDate>Thu, 04 Oct 2018 16:11:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Variable-dropping-from-data-set-after-calculation/m-p/501561#M534</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-04T16:11:34Z</dc:date>
    </item>
    <item>
      <title>Re: Variable dropping from data set after calculation</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Variable-dropping-from-data-set-after-calculation/m-p/501600#M543</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/238261"&gt;@Hazelc&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I'm a beginner so please be kind! I need some help with the SAS code below, I am using two&amp;nbsp;variables called&amp;nbsp;calvingdate and dob to create a new variable called afc. However, I still&amp;nbsp;need calvingdate to remain in&amp;nbsp;my dataset (it disappears when I run the code below).&amp;nbsp;Is&amp;nbsp;there any command that will allow me to keep calvingdate while still creating the new variable afc? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=together2;
by techid;
run;

data together2;
merge together2 (in=a) first_weight (in=b);
by techid;
if a and b;
run;

data together2;
set together2;
afc=calvingdate-dob;
run;

&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance!:)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Is the VARIABLE gone or are the values missing? And which data set(s)&amp;nbsp;contain the variables calvingdate and dob?&lt;/P&gt;
&lt;P&gt;IF first_weight has a missing value for calvingdate (or any other variable common with together2) then the value from first_weight replaced the value from together2. That is the way merge works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since your data step after the sort &lt;STRONG&gt;replaced&lt;/STRONG&gt; together2 with fewer records you will have to go back to a previous step and recreate the original together2.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 17:18:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Variable-dropping-from-data-set-after-calculation/m-p/501600#M543</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-04T17:18:30Z</dc:date>
    </item>
  </channel>
</rss>

