<?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: Can you use equal sign &amp;quot;=&amp;quot; to select two character variables with the exact value? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Can-you-use-equal-sign-quot-quot-to-select-two-character/m-p/717781#M222026</link>
    <description>&lt;P&gt;You can use = for your purpose without any issue.&amp;nbsp; [Edit: &lt;EM&gt;without&lt;/EM&gt;&amp;nbsp;instead of&lt;EM&gt; with&lt;/EM&gt; of course! &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt; ]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reasons seemingly identical strings don't match are:&lt;/P&gt;
&lt;P&gt;- Different numbers of leading spaces (trailing spaces do not matter)&lt;/P&gt;
&lt;P&gt;- Hidden non-printable characters (such as a tab instead of a space)&lt;/P&gt;
&lt;P&gt;- More obviously, case&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Feb 2021 07:15:10 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2021-02-09T07:15:10Z</dc:date>
    <item>
      <title>Can you use equal sign "=" to select two character variables with the exact value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-you-use-equal-sign-quot-quot-to-select-two-character/m-p/717770#M222022</link>
      <description>&lt;P&gt;In my case, I have a diagnosis year defined as yrdxcn and dxyear in character formats in two data sets. Upon merge, I want to select those with same values for yrdxcn and dxyear. Can I just the following?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data new; set old;&lt;/P&gt;&lt;P&gt;if yrdxcn = dxyear then output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The log file seemed OK. But the output seemed to tell me that I cannot perform "=" between two character variables because there was 0 observations in the output file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 01:53:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-you-use-equal-sign-quot-quot-to-select-two-character/m-p/717770#M222022</guid>
      <dc:creator>cashaowan</dc:creator>
      <dc:date>2021-02-09T01:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use equal sign "=" to select two character variables with the exact value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-you-use-equal-sign-quot-quot-to-select-two-character/m-p/717781#M222026</link>
      <description>&lt;P&gt;You can use = for your purpose without any issue.&amp;nbsp; [Edit: &lt;EM&gt;without&lt;/EM&gt;&amp;nbsp;instead of&lt;EM&gt; with&lt;/EM&gt; of course! &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt; ]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The reasons seemingly identical strings don't match are:&lt;/P&gt;
&lt;P&gt;- Different numbers of leading spaces (trailing spaces do not matter)&lt;/P&gt;
&lt;P&gt;- Hidden non-printable characters (such as a tab instead of a space)&lt;/P&gt;
&lt;P&gt;- More obviously, case&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 07:15:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-you-use-equal-sign-quot-quot-to-select-two-character/m-p/717781#M222026</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-02-09T07:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use equal sign "=" to select two character variables with the exact value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-you-use-equal-sign-quot-quot-to-select-two-character/m-p/717782#M222027</link>
      <description>&lt;P&gt;Yes you can. But you are only bringing data from one data set.&lt;/P&gt;
&lt;PRE&gt;data new; 
   set old; /* only the data set old is providing values as input*/
   if yrdxcn = dxyear then output;
run;&lt;/PRE&gt;
&lt;P&gt;The SET statement appends data so you likely need to Merge data. But to make much sense you normally merge on some sort of identification variables.&lt;/P&gt;
&lt;P&gt;An example providing some actual data (HINT)&lt;/P&gt;
&lt;P&gt;that Merges two data sets on a common identification value and does a comparison as you ask about AND and example of what happens when you use SET with two data sets.&lt;/P&gt;
&lt;PRE&gt;data one;
   input id char $;
datalines;
1  abc
2  xyz
3  pdq
;

data two;
   input id word $;
datalines;
1  abc
2  xyy
3  pdq
4  bbb
;

data example;
   merge one
         two
   ;
   by id;
   if char=word;
run;

data setexample;
  set one
      two
  ;
run;&lt;/PRE&gt;
&lt;P&gt;If you look at the Setexample data set you will see why if you use SET the comparison between Char and Word, using my variables, would never be equal: they do not appear on the same record with values because of the source.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To use merge with BY the both data sets will need to be sorted prior to use by the same variable(s) on the By statement.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 05:32:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-you-use-equal-sign-quot-quot-to-select-two-character/m-p/717782#M222027</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-09T05:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use equal sign "=" to select two character variables with the exact value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-you-use-equal-sign-quot-quot-to-select-two-character/m-p/717787#M222032</link>
      <description>The data old was a successfully merged data set. The data new was comparing two character variables in the merged data set.</description>
      <pubDate>Tue, 09 Feb 2021 06:11:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-you-use-equal-sign-quot-quot-to-select-two-character/m-p/717787#M222032</guid>
      <dc:creator>cashaowan</dc:creator>
      <dc:date>2021-02-09T06:11:22Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use equal sign "=" to select two character variables with the exact value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-you-use-equal-sign-quot-quot-to-select-two-character/m-p/717788#M222033</link>
      <description>&lt;P&gt;I think it is the first reason when I browse the data generated - there were leading spaces for the character variable created by the following. How to getting rid of the leading space when converting numeric variables to character variables?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data two; set one;&lt;/P&gt;&lt;P&gt;length dxyear $8.;&lt;/P&gt;&lt;P&gt;dxyear=put(dgyr, 8.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The steps above were used to convert the numeric variable dgyr (length: 8; Format: BEST 12.; Informat: 12.) to the character variable dxyear (length: 8; Format: $8.; Informat: $8.).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 06:23:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-you-use-equal-sign-quot-quot-to-select-two-character/m-p/717788#M222033</guid>
      <dc:creator>cashaowan</dc:creator>
      <dc:date>2021-02-09T06:23:16Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use equal sign "=" to select two character variables with the exact value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-you-use-equal-sign-quot-quot-to-select-two-character/m-p/717794#M222036</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/304913"&gt;@cashaowan&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;The data old was a successfully merged data set. The data new was comparing two character variables in the merged data set.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then SHOW the example data. Include at least some of the values that you think they should be equal.&lt;/P&gt;
&lt;P&gt;Your example should be in the form of a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A result of 0 observations means that none of the records in the merged data set have the two variables equal. A strong possibility is that the sets, while merged, did not merge in the desired order.&lt;/P&gt;
&lt;P&gt;Or that you actually have no matching values for some reason. You do need to show an actual example of values that you think are "equal" that are not creating the desired output.&lt;/P&gt;
&lt;P&gt;Better would be to rerun your code and copy from the LOG the entire data step with all the messages or notes that are generated and to paste the lines into a text box opened on the forum with the &amp;lt;/&amp;gt; icon. That will preserve the text as created in the log, otherwise the message windows on this forum &lt;STRONG&gt;will&lt;/STRONG&gt; reformat the text making some things not appear as they should.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 06:54:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-you-use-equal-sign-quot-quot-to-select-two-character/m-p/717794#M222036</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-09T06:54:18Z</dc:date>
    </item>
    <item>
      <title>Re: Can you use equal sign "=" to select two character variables with the exact value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Can-you-use-equal-sign-quot-quot-to-select-two-character/m-p/717796#M222038</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;&amp;nbsp;How to getting rid of the leading space when converting numeric variables to character variables?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Many ways. Use functions strip() or left().&lt;/P&gt;
&lt;P&gt;Or left justify the format:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TWO;
  set ONE;
  DXYEAR = put(DGYR, 8. -l);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Feb 2021 07:18:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Can-you-use-equal-sign-quot-quot-to-select-two-character/m-p/717796#M222038</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2021-02-09T07:18:06Z</dc:date>
    </item>
  </channel>
</rss>

