<?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: Refer to a character value when creating a new variable... in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Refer-to-a-character-value-when-creating-a-new-variable/m-p/328681#M73397</link>
    <description>&lt;P&gt;Great! It worked! Thanks&lt;/P&gt;</description>
    <pubDate>Tue, 31 Jan 2017 10:07:30 GMT</pubDate>
    <dc:creator>GKati</dc:creator>
    <dc:date>2017-01-31T10:07:30Z</dc:date>
    <item>
      <title>Refer to a character value when creating a new variable...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Refer-to-a-character-value-when-creating-a-new-variable/m-p/328676#M73392</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a large health&amp;nbsp;dataset with a character variable indicating the location of a health treatment. I am trying to create a dummy variable for certain cities.&lt;/P&gt;&lt;P&gt;Let's say:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data old;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set new;&lt;/P&gt;&lt;P&gt;nyc=0;&lt;/P&gt;&lt;P&gt;if location="New York" then nyc=1;&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that it doesn't seem to recognize either "New York" or New York without quotation marks and I&amp;nbsp;get all zeros. (I kow for a fact that at least 5% of the sample was in fact treated in NYC.&amp;nbsp;What could be the problem?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 09:57:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Refer-to-a-character-value-when-creating-a-new-variable/m-p/328676#M73392</guid>
      <dc:creator>GKati</dc:creator>
      <dc:date>2017-01-31T09:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: Refer to a character value when creating a new variable...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Refer-to-a-character-value-when-creating-a-new-variable/m-p/328678#M73394</link>
      <description>&lt;P&gt;Since you do not post any sample data this is just guessing..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But perhaps your character variable is cased differently than "New York". A common way to deal with this issue is to use the UPCASE function, such that your program looks like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data old;
    set new;
nyc=0;
if UPCASE(location) = "NEW YORK" then nyc=1;
output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Jan 2017 10:01:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Refer-to-a-character-value-when-creating-a-new-variable/m-p/328678#M73394</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-01-31T10:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: Refer to a character value when creating a new variable...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Refer-to-a-character-value-when-creating-a-new-variable/m-p/328679#M73395</link>
      <description>&lt;P&gt;btw you definately need the quotation marks &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 10:04:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Refer-to-a-character-value-when-creating-a-new-variable/m-p/328679#M73395</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-01-31T10:04:16Z</dc:date>
    </item>
    <item>
      <title>Re: Refer to a character value when creating a new variable...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Refer-to-a-character-value-when-creating-a-new-variable/m-p/328680#M73396</link>
      <description>&lt;P&gt;Text strings must match EXACTLY.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Run a PROC FREQ on location variable and see values. Note that string comparisons are case secsifive.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Use a HEX format to display variable and look for non printing blanks.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Use FIND/INDEX to search a string for partial values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And goes without saying, check your log for Notes/Warnings/Errors.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 10:04:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Refer-to-a-character-value-when-creating-a-new-variable/m-p/328680#M73396</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-01-31T10:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: Refer to a character value when creating a new variable...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Refer-to-a-character-value-when-creating-a-new-variable/m-p/328681#M73397</link>
      <description>&lt;P&gt;Great! It worked! Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 10:07:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Refer-to-a-character-value-when-creating-a-new-variable/m-p/328681#M73397</guid>
      <dc:creator>GKati</dc:creator>
      <dc:date>2017-01-31T10:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: Refer to a character value when creating a new variable...</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Refer-to-a-character-value-when-creating-a-new-variable/m-p/328683#M73399</link>
      <description>&lt;P&gt;A quick and simple way to code a dataset, and to save you typing, if you just want a set number:&lt;/P&gt;
&lt;PRE&gt;proc sort data=your_dataset out=codelist nodupkey (keep=location);
  by location;
run;

data codelist;
  set codelist;
  code=_n_;
run;

proc sql;
  create table WANT as
  select  A.*,
          B.CODE
  from    YOUR_DATASET A
  left join CODELIST B
  on      A.LOCATION=B.LOCATION;
quit;&lt;/PRE&gt;
&lt;P&gt;What this does is create a table with distinct locations, and assigns 1-x based on sort order (obviously you could change the sort if you wanted), then merges that back onto your original data. &amp;nbsp;In this way you don't need to type each if statement, and don't need to worry about "your string" not being the same as "data string" as both come from the same. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 10:27:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Refer-to-a-character-value-when-creating-a-new-variable/m-p/328683#M73399</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-31T10:27:15Z</dc:date>
    </item>
  </channel>
</rss>

