<?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: Making changes to records in SAS dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Making-changes-to-records-in-SAS-dataset/m-p/423219#M280889</link>
    <description>&lt;P&gt;Sounds like what you basically want to do is to change the value of the MASS variable to the number of records having that last name and DOB?&lt;/P&gt;&lt;P&gt;Something like this may work:&lt;/P&gt;&lt;PRE&gt;proc sort data=have;
  by last_name DOB;
run;

data counts;
  do mass=1 by 1 until(last.DOB);
    set have(keep=last_name DOB);
    by last_name DOB;
    end;
run;

data want;
  merge have(drop=mass) counts;
  by last_name DOB;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 21 Dec 2017 21:14:56 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2017-12-21T21:14:56Z</dc:date>
    <item>
      <title>Making changes to records in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-changes-to-records-in-SAS-dataset/m-p/422340#M280887</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a SAS dataset and I want to change the value of certain variables in the dataset. I’ve identified records (9-10) that have incorrect values and have their last name, DOB, and the variable called Mass that needs to be corrected. There are two different types of change that need to happen. For instance,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;The record that belongs to someone whose last name-Mendez and DOB-7/9/14 I want to change the value of Mass from 2 to 1.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;The record that belongs to someone whose last name-Williams and DOB-2/2/77 I want to keep the variable Mass 2 as it is AND find another record with the same last name and DOB (other values such as first name, weight will be different) and change the value of Mass from 1 to 2. Similiarly, if I find more than one matching record I want SAS to generate the total # of these matching records. For instance, if there are 4 matching records whose last name is Williams and DOB 2/2/77, Mass should be 4.&amp;nbsp;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I plan to do this for each of those 10 records with incorrect values using last name and DOB. Does anyone know how to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 16:16:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-changes-to-records-in-SAS-dataset/m-p/422340#M280887</guid>
      <dc:creator>Kiko</dc:creator>
      <dc:date>2017-12-19T16:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: Making changes to records in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-changes-to-records-in-SAS-dataset/m-p/422346#M280888</link>
      <description>&lt;P&gt;Use IF THEN statements and include lots of comments to explain why you're doing this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or create a data set with the correct information and then use an UPDATE statement to update the data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if last_name = 'Mendez' and dob = '09Jul2014'd then mass=2; -&amp;gt; are you sure this won't catch other records?&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If it will catch other records you can consider hard coding it, if you know the row numbers but this is a bad idea in my opinion. If the data is out of expected order you'll change the wrong record. You can reference the row using _n_.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if _n_ = 4 then mass=2; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/135005"&gt;@Kiko&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a SAS dataset and I want to change the value of certain variables in the dataset. I’ve identified records (9-10) that have incorrect values and have their last name, DOB, and the variable called Mass that needs to be corrected. There are two different types of change that need to happen. For instance,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The record that belongs to someone whose last name-Mendez and DOB-7/9/14 I want to change the value of Mass from 2 to 1.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The record that belongs to someone whose last name-Williams and DOB-2/2/77 I want to keep the variable Mass 2 as it is AND find another record with the same last name and DOB (other values such as first name, weight will be different) and change the value of Mass from 1 to 2. Similiarly, if I find more than one matching record I want SAS to generate the total # of these matching records. For instance, if there are 4 matching records whose last name is Williams and DOB 2/2/77, Mass should be 4.&amp;nbsp;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I plan to do this for each of those 10 records with incorrect values using last name and DOB. Does anyone know how to do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Dec 2017 16:22:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-changes-to-records-in-SAS-dataset/m-p/422346#M280888</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-12-19T16:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: Making changes to records in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-changes-to-records-in-SAS-dataset/m-p/423219#M280889</link>
      <description>&lt;P&gt;Sounds like what you basically want to do is to change the value of the MASS variable to the number of records having that last name and DOB?&lt;/P&gt;&lt;P&gt;Something like this may work:&lt;/P&gt;&lt;PRE&gt;proc sort data=have;
  by last_name DOB;
run;

data counts;
  do mass=1 by 1 until(last.DOB);
    set have(keep=last_name DOB);
    by last_name DOB;
    end;
run;

data want;
  merge have(drop=mass) counts;
  by last_name DOB;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Dec 2017 21:14:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-changes-to-records-in-SAS-dataset/m-p/423219#M280889</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2017-12-21T21:14:56Z</dc:date>
    </item>
    <item>
      <title>Re: Making changes to records in SAS dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Making-changes-to-records-in-SAS-dataset/m-p/423261#M280890</link>
      <description>&lt;P&gt;I wouldn't change the original data, make a new dataset that has the new information.&lt;/P&gt;
&lt;P&gt;PROC SQL can merge summary statistics onto detail rows for you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table want as 
select *,count(*) as MASS
from have
group by last_name, DOB
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;If for some reason your original dataset already has a variable named MASS then you will need to drop that on the way in by using the DROP= dataset option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;from have (drop=MASS)&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 22 Dec 2017 06:21:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Making-changes-to-records-in-SAS-dataset/m-p/423261#M280890</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-12-22T06:21:05Z</dc:date>
    </item>
  </channel>
</rss>

