<?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: Data step calculations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-step-calculations/m-p/50693#M10584</link>
    <description>I used the "not equal" for both cases...meaning if there is a value for both Y and Z (implies observation of X matches) then overwrite Z.  Getting around the creation of new variables. Pretty sure both will work similarly, I've never used the "in" in that way though.</description>
    <pubDate>Wed, 01 Oct 2008 18:00:12 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2008-10-01T18:00:12Z</dc:date>
    <item>
      <title>Data step calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-calculations/m-p/50690#M10581</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I've two data sets file1 and file2&lt;BR /&gt;
&lt;BR /&gt;
file1 contains variables X and Z&lt;BR /&gt;
file2 contains variables X and Y&lt;BR /&gt;
&lt;BR /&gt;
I've the values of X in both the datasets and I also have the values of Y in file2.&lt;BR /&gt;
&lt;BR /&gt;
Now i've to write a code where the condition is:&lt;BR /&gt;
&lt;BR /&gt;
where file1:X=file2:X then Z=Y*1000&lt;BR /&gt;
&lt;BR /&gt;
Can you please tell me how I should be coding this.&lt;BR /&gt;
&lt;BR /&gt;
Thanks,</description>
      <pubDate>Tue, 30 Sep 2008 18:26:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-calculations/m-p/50690#M10581</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-09-30T18:26:11Z</dc:date>
    </item>
    <item>
      <title>Re: Data step calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-calculations/m-p/50691#M10582</link>
      <description>It sounds like from your post that file1:X is not always equal to file2:X, but sometimes it is...and if it is are equal you want Z to be overwritten with Y*1000.  If that is the case&lt;BR /&gt;
&lt;BR /&gt;
merge the datasets by X that will take care of the "where file1:X = file2:X" part.&lt;BR /&gt;
&lt;BR /&gt;
then knowing that the merge will fill any non-equivalent data with missing data&lt;BR /&gt;
you can use:  if Y ^= . and Z ^= . then Z = Y * 1000;&lt;BR /&gt;
&lt;BR /&gt;
your end solution should be:&lt;BR /&gt;
&lt;BR /&gt;
data file3;&lt;BR /&gt;
merge file1 file2;&lt;BR /&gt;
by X;&lt;BR /&gt;
if Y ^= . and Z ^= . then Z = Y * 1000;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
caution you still may have missing data both Y and Z.&lt;BR /&gt;
&lt;BR /&gt;
johnny</description>
      <pubDate>Tue, 30 Sep 2008 23:18:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-calculations/m-p/50691#M10582</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-09-30T23:18:48Z</dc:date>
    </item>
    <item>
      <title>Re: Data step calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-calculations/m-p/50692#M10583</link>
      <description>As I understand it the calculation should only happen if the observations match. To control that "in" can be used. Based on the already given example:&lt;BR /&gt;
&lt;BR /&gt;
data file3;&lt;BR /&gt;
merge file1 (in=MyDS1) file2 (in=MyDS2);&lt;BR /&gt;
by X;&lt;BR /&gt;
&lt;BR /&gt;
/* do the following only if there is a matching record */&lt;BR /&gt;
if MyDS1 and MyDS2 then Z = Y * 1000;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
In case that Y is missing, Z will be missing as well. If you don't want that then just add a bit more logic (have a look at "ifn" in the SAS OnlineDoc).&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Wed, 01 Oct 2008 13:13:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-calculations/m-p/50692#M10583</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2008-10-01T13:13:53Z</dc:date>
    </item>
    <item>
      <title>Re: Data step calculations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-step-calculations/m-p/50693#M10584</link>
      <description>I used the "not equal" for both cases...meaning if there is a value for both Y and Z (implies observation of X matches) then overwrite Z.  Getting around the creation of new variables. Pretty sure both will work similarly, I've never used the "in" in that way though.</description>
      <pubDate>Wed, 01 Oct 2008 18:00:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-step-calculations/m-p/50693#M10584</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-10-01T18:00:12Z</dc:date>
    </item>
  </channel>
</rss>

