<?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 use diff function for character variables ? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-diff-function-for-character-variables/m-p/91151#M26032</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi PGStats, Art and Hai.Kuo,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks for every one of you. All three codes are working well.&lt;/P&gt;&lt;P&gt;(I cannot click "correct answer" for all three responses for some reason) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hi Art,&lt;/P&gt;&lt;P&gt;Now only I realized that what I have used is not diff function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again! &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mirisage&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Aug 2012 01:22:40 GMT</pubDate>
    <dc:creator>Mirisage</dc:creator>
    <dc:date>2012-08-12T01:22:40Z</dc:date>
    <item>
      <title>How to use diff function for character variables ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-diff-function-for-character-variables/m-p/91147#M26028</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="background: yellow; font-size: 10pt;"&gt;Hi Forum,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: yellow; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: yellow; font-size: 10pt;"&gt;In the attached dataset, I need to see if the “Balance” of duplicate accounts are identical or not. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: yellow; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: yellow; font-size: 10pt;"&gt;E.g. Account_number 111 has two records. “Balance” of each record are 25. So, they are identical.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000; text-decoration: underline;"&gt;&lt;SPAN style="font-size: 10pt; text-decoration: underline;"&gt;My approach.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;I used diff function (from Cody’s book).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;SET&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; tt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;BY&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; account_number;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: green; font-size: 11pt;"&gt;*REMOVE accounts WITH ONE record ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;IF&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; FIRST.account_number &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;AND&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; LAST.account_number&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;THEN&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; DELETE;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;RETAIN&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; R_HR ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;IF&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; FIRST.account_number &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;THEN&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;DO&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;R_HR = balance;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;END&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;IF&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; LAST.account_number &lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;THEN&lt;/SPAN&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;DO&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;DIFF_HR = balance - R_HR;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;OUTPUT&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;END&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;DROP&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; R_: ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;RUN&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt;&amp;nbsp; &lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;freq&lt;/STRONG&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;data&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; = want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 11pt;"&gt;tables&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; DIFF_HR;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="text-decoration: underline;"&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: fuchsia; font-size: 11pt; text-decoration: underline;"&gt;Question:&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #339966; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;I want to determine if the values of “arrears_band” variable are also identical or not in duplicate accounts.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #339966; font-size: 11pt; background: white; font-family: 'Courier New';"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #339966; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;I do not know how to use diff function for “character” variable.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #339966; font-size: 11pt; background: white; font-family: 'Courier New';"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #339966; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;Could any one of you help me?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;Mirisage &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Aug 2012 21:49:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-diff-function-for-character-variables/m-p/91147#M26028</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2012-08-11T21:49:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to use diff function for character variables ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-diff-function-for-character-variables/m-p/91148#M26029</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you don't mind an SQL answer :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;select account_number from sasforum.Post_this&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;group by account_number&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;having count(distinct Arrears_band) &amp;gt; 1;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Aug 2012 22:23:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-diff-function-for-character-variables/m-p/91148#M26029</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2012-08-11T22:23:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to use diff function for character variables ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-diff-function-for-character-variables/m-p/91149#M26030</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You said you used the dif function, but that isn't shown in your code.&amp;nbsp; Anyhow, to answer your question, the dif function is limited to numeric variables.&amp;nbsp; You could accomplish the same thing with the lag function.&amp;nbsp; e.g.:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want (keep=account_number identical);&lt;/P&gt;&lt;P&gt;&amp;nbsp; SET tt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; BY account_number;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain identical;&lt;/P&gt;&lt;P&gt;&amp;nbsp; last_arrears_band=lag(arrears_band);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if not(FIRST.account_number and LAST.account_number);&lt;/P&gt;&lt;P&gt;&amp;nbsp; IF FIRST.account_number then identical=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if arrears_band ne last_arrears_band then identical=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; IF last.account_number&amp;nbsp; THEN output;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Aug 2012 23:00:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-diff-function-for-character-variables/m-p/91149#M26030</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-08-11T23:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to use diff function for character variables ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-diff-function-for-character-variables/m-p/91150#M26031</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you only care about first or last of each group like your original code shows, then a small tweak will be sufficient do what you want for character variable:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;SET tt;&lt;/P&gt;&lt;P&gt;BY account_number;&lt;/P&gt;&lt;P&gt;*REMOVE accounts WITH ONE record ;&lt;/P&gt;&lt;P&gt;IF FIRST.account_number AND LAST.account_number&lt;/P&gt;&lt;P&gt;THEN DELETE;&lt;/P&gt;&lt;P&gt;RETAIN r_ab ;&lt;/P&gt;&lt;P&gt;IF FIRST.account_number then r_ab = Arrears_Band;&lt;/P&gt;&lt;P&gt;IF LAST.account_number THEN DO;&lt;/P&gt;&lt;P&gt;DIFF_AB = &lt;STRONG&gt;(Arrears_Band = r_ab)&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;OUTPUT;&lt;/P&gt;&lt;P&gt;END;&lt;/P&gt;&lt;P&gt;DROP R_:;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically, beside changing variable names, the only change need to be made is to replace the minus sign '-' with equal sign '='.&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Aug 2012 23:08:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-diff-function-for-character-variables/m-p/91150#M26031</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-08-11T23:08:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to use diff function for character variables ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-use-diff-function-for-character-variables/m-p/91151#M26032</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi PGStats, Art and Hai.Kuo,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks for every one of you. All three codes are working well.&lt;/P&gt;&lt;P&gt;(I cannot click "correct answer" for all three responses for some reason) &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hi Art,&lt;/P&gt;&lt;P&gt;Now only I realized that what I have used is not diff function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks again! &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Mirisage&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Aug 2012 01:22:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-use-diff-function-for-character-variables/m-p/91151#M26032</guid>
      <dc:creator>Mirisage</dc:creator>
      <dc:date>2012-08-12T01:22:40Z</dc:date>
    </item>
  </channel>
</rss>

