<?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: How to replace the value of a variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-value-of-a-variable/m-p/784019#M250114</link>
    <description>&lt;P&gt;Your code does not show a SET statement for a data source. That is the first thing.&lt;/P&gt;
&lt;P&gt;The IN operator requires ( ) around the values. The log would show that if you supply a data set.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;180  data junk;
181     set sashelp.class;
182     if sex in "F" then sex="A";
                  ---
                  390
                  200
                  76
ERROR 390-185: Expecting an relational or arithmetic operator.

ERROR 200-322: The symbol is not recognized and will be ignored.

ERROR 76-322: Syntax error, statement will be ignored.

183  run;
&lt;/PRE&gt;
&lt;P&gt;Since you have two values for CA I would suggest something similar to this to take advantage of the way the IN operator works:&lt;/P&gt;
&lt;PRE&gt;data test_output;
   set yourdatagoeshere;
   if jurisdiction in ("LAX" "SF") then jurisdiction = "CA";
   else if jurisdiction = "NYC" then jurisdiction = "NY";
run;&lt;/PRE&gt;
&lt;P&gt;I used an ELSE because it is a good habit to get into with this sort of recoding as it is possible to have a number of changes and you might end up undoing a previous assignment. Also more complex conditions using multiple variables can get you into that mess quickly.&lt;/P&gt;
&lt;P&gt;The SELECT/WHEN/END construct may be easier to follow and write if you have more than one or two reassignments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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/400162"&gt;@SAS_learneromg&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a big dataset of medical test results that includes a "jurisdiction" variable for the state where the person had their testing done. SO for most people the value of jurisdiction is FL, GA. Except for people who were tested in New York City, Los Angeles and San Francisco, they have values of "NYC" "LAX" and "SF". For my purposes, I just want state level data. Is there was was to change "LAX" and "SF" to "CA", and "NYC to "NY" without having to create a new variable. This is the code I tried:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test_output;&lt;/P&gt;
&lt;P&gt;if jurisdiction in "LAX" then jurisdiction = "CA";&lt;/P&gt;
&lt;P&gt;if jurisdiction in "SF" then jurisdiction = "CA";&lt;/P&gt;
&lt;P&gt;if jurisdiction in "NYC" then jurisdiction = "NY";&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That didn't work so I must be missing something. Any tips?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Dec 2021 21:33:29 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-12-03T21:33:29Z</dc:date>
    <item>
      <title>How to replace the value of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-value-of-a-variable/m-p/784015#M250112</link>
      <description>&lt;P&gt;I have a big dataset of medical test results that includes a "jurisdiction" variable for the state where the person had their testing done. SO for most people the value of jurisdiction is FL, GA. Except for people who were tested in New York City, Los Angeles and San Francisco, they have values of "NYC" "LAX" and "SF". For my purposes, I just want state level data. Is there was was to change "LAX" and "SF" to "CA", and "NYC to "NY" without having to create a new variable. This is the code I tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test_output;&lt;/P&gt;&lt;P&gt;if jurisdiction in "LAX" then jurisdiction = "CA";&lt;/P&gt;&lt;P&gt;if jurisdiction in "SF" then jurisdiction = "CA";&lt;/P&gt;&lt;P&gt;if jurisdiction in "NYC" then jurisdiction = "NY";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That didn't work so I must be missing something. Any tips?&lt;/P&gt;</description>
      <pubDate>Fri, 03 Dec 2021 20:58:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-value-of-a-variable/m-p/784015#M250112</guid>
      <dc:creator>SAS_learneromg</dc:creator>
      <dc:date>2021-12-03T20:58:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace the value of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-value-of-a-variable/m-p/784019#M250114</link>
      <description>&lt;P&gt;Your code does not show a SET statement for a data source. That is the first thing.&lt;/P&gt;
&lt;P&gt;The IN operator requires ( ) around the values. The log would show that if you supply a data set.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;180  data junk;
181     set sashelp.class;
182     if sex in "F" then sex="A";
                  ---
                  390
                  200
                  76
ERROR 390-185: Expecting an relational or arithmetic operator.

ERROR 200-322: The symbol is not recognized and will be ignored.

ERROR 76-322: Syntax error, statement will be ignored.

183  run;
&lt;/PRE&gt;
&lt;P&gt;Since you have two values for CA I would suggest something similar to this to take advantage of the way the IN operator works:&lt;/P&gt;
&lt;PRE&gt;data test_output;
   set yourdatagoeshere;
   if jurisdiction in ("LAX" "SF") then jurisdiction = "CA";
   else if jurisdiction = "NYC" then jurisdiction = "NY";
run;&lt;/PRE&gt;
&lt;P&gt;I used an ELSE because it is a good habit to get into with this sort of recoding as it is possible to have a number of changes and you might end up undoing a previous assignment. Also more complex conditions using multiple variables can get you into that mess quickly.&lt;/P&gt;
&lt;P&gt;The SELECT/WHEN/END construct may be easier to follow and write if you have more than one or two reassignments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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/400162"&gt;@SAS_learneromg&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a big dataset of medical test results that includes a "jurisdiction" variable for the state where the person had their testing done. SO for most people the value of jurisdiction is FL, GA. Except for people who were tested in New York City, Los Angeles and San Francisco, they have values of "NYC" "LAX" and "SF". For my purposes, I just want state level data. Is there was was to change "LAX" and "SF" to "CA", and "NYC to "NY" without having to create a new variable. This is the code I tried:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data test_output;&lt;/P&gt;
&lt;P&gt;if jurisdiction in "LAX" then jurisdiction = "CA";&lt;/P&gt;
&lt;P&gt;if jurisdiction in "SF" then jurisdiction = "CA";&lt;/P&gt;
&lt;P&gt;if jurisdiction in "NYC" then jurisdiction = "NY";&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That didn't work so I must be missing something. Any tips?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Dec 2021 21:33:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-value-of-a-variable/m-p/784019#M250114</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-12-03T21:33:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace the value of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-value-of-a-variable/m-p/784020#M250115</link>
      <description>That did the trick! Thanks for that explanation. Don't know I forgot my set statement lol.</description>
      <pubDate>Fri, 03 Dec 2021 21:44:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-the-value-of-a-variable/m-p/784020#M250115</guid>
      <dc:creator>SAS_learneromg</dc:creator>
      <dc:date>2021-12-03T21:44:21Z</dc:date>
    </item>
  </channel>
</rss>

