<?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: edit observation in a SAS data set in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/edit-observation-in-a-SAS-data-set/m-p/818234#M34614</link>
    <description>Hi Kurt,&lt;BR /&gt;Thank you so much for your kind support and advice. Yes, the code you provided is working. Amazing!!!!!!!Thanks</description>
    <pubDate>Wed, 15 Jun 2022 00:07:04 GMT</pubDate>
    <dc:creator>Uddin</dc:creator>
    <dc:date>2022-06-15T00:07:04Z</dc:date>
    <item>
      <title>edit observation in a SAS data set</title>
      <link>https://communities.sas.com/t5/New-SAS-User/edit-observation-in-a-SAS-data-set/m-p/818105#M34586</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a data set where I want to edit observation. For example, the data set contains country names under 'country' variable like:&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Country&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Finland&lt;/P&gt;&lt;P&gt;Denmark&lt;/P&gt;&lt;P&gt;Norway&lt;/P&gt;&lt;P&gt;Iceland&lt;/P&gt;&lt;P&gt;Netherlands&lt;/P&gt;&lt;P&gt;Switzerland&lt;/P&gt;&lt;P&gt;Sweden&lt;/P&gt;&lt;P&gt;New Zeland&lt;/P&gt;&lt;P&gt;Canada&lt;/P&gt;&lt;P&gt;Austria&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to edit "Switzerland" into "Swiss" and "Iceland" into "Nordic island" . I tried with replace statement but it is not working. Could you please help me regarding this. Looking for your kind response.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2022 15:03:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/edit-observation-in-a-SAS-data-set/m-p/818105#M34586</guid>
      <dc:creator>Uddin</dc:creator>
      <dc:date>2022-06-14T15:03:30Z</dc:date>
    </item>
    <item>
      <title>Re: edit observation in a SAS data set</title>
      <link>https://communities.sas.com/t5/New-SAS-User/edit-observation-in-a-SAS-data-set/m-p/818107#M34587</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I tried with replace statement but it is not working.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;For your current and future benefit, never tell us something doesn't work and provide no other information.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;We don't know what you did, and we don't know why it isn't working. We can't help. But if you show us, we can help. Show us the entire LOG for this step, copy the entire log for this PROC or DATA step and paste it into the window that appears when you click on the &amp;lt;/&amp;gt; icon.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2021-11-26 08_27_29-Reply to Message - SAS Support Communities — Mozilla Firefox.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66123iA4EF494F9CA0F6EE/image-size/large?v=v2&amp;amp;px=999" role="button" title="2021-11-26 08_27_29-Reply to Message - SAS Support Communities — Mozilla Firefox.png" alt="2021-11-26 08_27_29-Reply to Message - SAS Support Communities — Mozilla Firefox.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2022 15:11:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/edit-observation-in-a-SAS-data-set/m-p/818107#M34587</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-14T15:11:30Z</dc:date>
    </item>
    <item>
      <title>Re: edit observation in a SAS data set</title>
      <link>https://communities.sas.com/t5/New-SAS-User/edit-observation-in-a-SAS-data-set/m-p/818111#M34588</link>
      <description>&lt;P&gt;Two ways: use a SELECT or a format in a data step.&lt;/P&gt;
&lt;P&gt;1)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
select (country);
  when ("Switzerland") country = "Swiss";
  when ("Iceland") country = "Nordic island";
  otherwise;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value $transcountry
  "Switzerland" = "Swiss"
  "Iceland" = "Nordic island"
;
run;

data want;
set have;
country = put(country,$transcountry.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Jun 2022 15:16:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/edit-observation-in-a-SAS-data-set/m-p/818111#M34588</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-06-14T15:16:49Z</dc:date>
    </item>
    <item>
      <title>Re: edit observation in a SAS data set</title>
      <link>https://communities.sas.com/t5/New-SAS-User/edit-observation-in-a-SAS-data-set/m-p/818115#M34589</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Sorry for that and thanks for your advice. Here is the Code I used:&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;Country="Swiss";&lt;BR /&gt;Replace var Country where Country="Switzerland";&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Looking for your kind response.&lt;BR /&gt;&lt;BR /&gt;Kind Regards&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 14 Jun 2022 15:25:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/edit-observation-in-a-SAS-data-set/m-p/818115#M34589</guid>
      <dc:creator>Uddin</dc:creator>
      <dc:date>2022-06-14T15:25:14Z</dc:date>
    </item>
    <item>
      <title>Re: edit observation in a SAS data set</title>
      <link>https://communities.sas.com/t5/New-SAS-User/edit-observation-in-a-SAS-data-set/m-p/818119#M34590</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/427395"&gt;@Uddin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;Sorry for that and thanks for your advice. Here is the Code I used:&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;Country="Swiss";&lt;BR /&gt;Replace var Country where Country="Switzerland";&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Looking for your kind response.&lt;BR /&gt;&lt;BR /&gt;Kind Regards&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;As far as I know that isn't valid SAS syntax. Are you using SAS Studio, CAS? VA?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;EDIT: Looks like this is IML function, are you programming using SAS IML?&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.3/imlug/imlug_langref_sect392.htm#:~:text=The%20REPLACE%20statement%20replaces%20the,as%20the%20data%20set%20variables" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.3/imlug/imlug_langref_sect392.htm#:~:text=The%20REPLACE%20statement%20replaces%20the,as%20the%20data%20set%20variables&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2022 15:48:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/edit-observation-in-a-SAS-data-set/m-p/818119#M34590</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-06-14T15:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: edit observation in a SAS data set</title>
      <link>https://communities.sas.com/t5/New-SAS-User/edit-observation-in-a-SAS-data-set/m-p/818122#M34591</link>
      <description>&lt;P&gt;To change the value of a variable just assign a new value.&amp;nbsp; Your code already includes an assignment statement, but it is unconditional so it will change COUNTRY to Swiss on every observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So just execute the assignment statement conditionally.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
  if Country="Switzerland" then Country="Swiss";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you read the statement out loud it does what it says.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2022 15:32:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/edit-observation-in-a-SAS-data-set/m-p/818122#M34591</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-14T15:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: edit observation in a SAS data set</title>
      <link>https://communities.sas.com/t5/New-SAS-User/edit-observation-in-a-SAS-data-set/m-p/818126#M34592</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/427395"&gt;@Uddin&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you really want to use the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p103b0p9akdcmhn1xbik9hbuo760.htm" target="_blank" rel="noopener"&gt;REPLACE statement&lt;/A&gt; (i.e., edit dataset HAVE &lt;EM&gt;in place&lt;/EM&gt;, not rewriting the unchanged observations), here's how it works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
modify have;
if country='Switzerland' then do;
  country='Swiss';
  replace;
end;
else if country='Iceland' then do;
  country='Nordic island';
  replace;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or, alternatively, with only one REPLACE statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
modify have;
w=whichc(country, 'Switzerland', 'Iceland');
if w then do;
  country=choosec(w, 'Swiss', 'Nordic island');
  replace;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Jun 2022 15:44:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/edit-observation-in-a-SAS-data-set/m-p/818126#M34592</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-06-14T15:44:08Z</dc:date>
    </item>
    <item>
      <title>Re: edit observation in a SAS data set</title>
      <link>https://communities.sas.com/t5/New-SAS-User/edit-observation-in-a-SAS-data-set/m-p/818129#M34593</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/427395"&gt;@Uddin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;Sorry for that and thanks for your advice. Here is the Code I used:&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;Country="Swiss";&lt;BR /&gt;Replace var Country where Country="Switzerland";&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Looking for your kind response.&lt;BR /&gt;&lt;BR /&gt;Kind Regards&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Maxim 1: Read the Documentation.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p103b0p9akdcmhn1xbik9hbuo760.htm" target="_blank" rel="noopener"&gt;REPLACE Statement&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will immediately see that REPLACE is not the correct tool to use.&lt;/P&gt;
&lt;P&gt;The most simple version is this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if country = "Switzerland" then country = "Swiss";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I have already shown two ways to do that for multiple values.&lt;/P&gt;
&lt;P&gt;For more than a few values, store the original and replacement values in a dataset, from which you can either create the format, or which you can use in a join, or which you can use as a source for a hash object.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jun 2022 15:50:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/edit-observation-in-a-SAS-data-set/m-p/818129#M34593</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-06-14T15:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: edit observation in a SAS data set</title>
      <link>https://communities.sas.com/t5/New-SAS-User/edit-observation-in-a-SAS-data-set/m-p/818234#M34614</link>
      <description>Hi Kurt,&lt;BR /&gt;Thank you so much for your kind support and advice. Yes, the code you provided is working. Amazing!!!!!!!Thanks</description>
      <pubDate>Wed, 15 Jun 2022 00:07:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/edit-observation-in-a-SAS-data-set/m-p/818234#M34614</guid>
      <dc:creator>Uddin</dc:creator>
      <dc:date>2022-06-15T00:07:04Z</dc:date>
    </item>
    <item>
      <title>Re: edit observation in a SAS data set</title>
      <link>https://communities.sas.com/t5/New-SAS-User/edit-observation-in-a-SAS-data-set/m-p/818236#M34615</link>
      <description>Hi Reeza,&lt;BR /&gt;Thank you so much for your kind response. I am using SAS studio. Kind Regards&lt;BR /&gt;</description>
      <pubDate>Wed, 15 Jun 2022 00:10:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/edit-observation-in-a-SAS-data-set/m-p/818236#M34615</guid>
      <dc:creator>Uddin</dc:creator>
      <dc:date>2022-06-15T00:10:14Z</dc:date>
    </item>
    <item>
      <title>Re: edit observation in a SAS data set</title>
      <link>https://communities.sas.com/t5/New-SAS-User/edit-observation-in-a-SAS-data-set/m-p/818238#M34616</link>
      <description>Hi Tom,&lt;BR /&gt;&lt;BR /&gt;Thanks for your effort and advice. Yes, the code you provided is working. Brilliant!!!!!!</description>
      <pubDate>Wed, 15 Jun 2022 00:17:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/edit-observation-in-a-SAS-data-set/m-p/818238#M34616</guid>
      <dc:creator>Uddin</dc:creator>
      <dc:date>2022-06-15T00:17:31Z</dc:date>
    </item>
  </channel>
</rss>

