<?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: character question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309248#M66501</link>
    <description>&lt;P&gt;Thanks. I got it.&lt;/P&gt;</description>
    <pubDate>Fri, 04 Nov 2016 13:19:52 GMT</pubDate>
    <dc:creator>Niugg2010</dc:creator>
    <dc:date>2016-11-04T13:19:52Z</dc:date>
    <item>
      <title>character question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309085#M66449</link>
      <description>&lt;P&gt;I have two gene sequences&lt;/P&gt;&lt;P&gt;(1)&lt;SPAN&gt;GAGCAAGCGCCATACTCCTGTGGAGAAGTCTGCCGTTACTGCCCTGTGGGGCAAGGTGAACGTGGA&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;(2)&lt;SPAN&gt;GAGCAAGCGCCATAGTCCTGTGGAGAAGTCTGCCGTTACTGCCCTGTGGGGCAAGGTGAACGTGGA&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to mark their differences.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now&amp;nbsp;I marked the differences with lowcase(char) (see my code below). My question is how I can mark the difference with &lt;FONT color="#FF0000"&gt;Red&lt;/FONT&gt; color.&lt;/P&gt;&lt;P&gt;By the way, I appreciate if someone can optimize my code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&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;***Code Start*******************************************&lt;/P&gt;&lt;P&gt;data a;&lt;BR /&gt;length f1 $ 200;&lt;BR /&gt;input f1;&lt;BR /&gt;datalines;&lt;BR /&gt;GAGCAAGCGCCATACTCCTGTGGAGAAGTCTGCCGTTACTGCCCTGTGGGGCAAGGTGAACGTGGA&lt;BR /&gt;GAGCAAGCGCCATAGTCCTGTGGAGAAGTCTGCCGTTACTGCCCTGTGGGGCAAGGTGAACGTGGA&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;data b;&lt;BR /&gt;set a;&lt;BR /&gt;retain base len_1;&lt;BR /&gt;if _n_=1 then&lt;BR /&gt;do;&lt;BR /&gt;base=f1;&lt;BR /&gt;len_1=length(base);&lt;BR /&gt;end;&lt;BR /&gt;f2=f1;&lt;BR /&gt;len_2=length(f2);&lt;BR /&gt;x=min(len_1, len_2);&lt;BR /&gt;do i=1 to x;&lt;BR /&gt;substr_1=substr(base,i,1);&lt;BR /&gt;substr_2=substr(f2,i,1);&lt;BR /&gt;if substr_1 ^=substr_2 then substr(f2,i,1)=lowcase(substr_2);&lt;BR /&gt;else;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc print data=b ;&lt;BR /&gt;var f1 f2;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;***Code end***********************************&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>Thu, 03 Nov 2016 16:32:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309085#M66449</guid>
      <dc:creator>Niugg2010</dc:creator>
      <dc:date>2016-11-03T16:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: character question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309087#M66451</link>
      <description>&lt;P&gt;Color implies a method of display that includes such things. So the question to you is what output format are you looking for as addressing individual characters will likley require different methods. Do you want HTML, RTF, PDF or something else for output.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 16:45:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309087#M66451</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-03T16:45:09Z</dc:date>
    </item>
    <item>
      <title>Re: character question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309095#M66453</link>
      <description>&lt;P&gt;RTF or PDF are both fine for me.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you mean to use proc template to control the output? In my mind, Proc template can only define to CELLVALUE level, not the special character in each CELL.&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>Thu, 03 Nov 2016 17:34:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309095#M66453</guid>
      <dc:creator>Niugg2010</dc:creator>
      <dc:date>2016-11-03T17:34:24Z</dc:date>
    </item>
    <item>
      <title>Re: character question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309102#M66457</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/100692"&gt;@Niugg2010&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;RTF or PDF are both fine for me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you mean to use proc template to control the output? In my mind, Proc template can only define to CELLVALUE level, not the special character in each CELL.&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;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Thats why the target definition is important. The only way I see likely is to build a string with inbeded markup codes. A pseudo code approach is going to yield a string that lools something&amp;nbsp;like the following where {font color: color value} is replaced by the raw codes of the markup destination.&lt;/P&gt;
&lt;P&gt;{font color: default}ABCABCABC{font color:red}abc{font color:default}BDABDABDA&lt;/P&gt;
&lt;P&gt;using letters intentionally that do not resemble your data in any detail.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ESCAPECHAR and the RAW function will let you insert the control strings once the values needed are determined.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would recommend hard coding a couple of examples to get the feel before trying to code conditionally based on the case of the letters. The latter shouldn't be to difficult actually once the correct code is determined.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a real brief example of inserting codes to print, change the RTF filepath to something you can use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods escapchar="^";
data junk;

x = 'Example of ^{raw \cf12 RAW} function';
y ="Example ^{style [foreground=red] of Super, Alpha ^{super ^{unicode ALPHA}
       ^{style [foreground=green] Nested}} Formatting} and Scoping";
run;

ods rtf file='D:\data\junk.rtf' style=meadow;
proc print data=junk;
run;
ods rtf close;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Nov 2016 18:14:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309102#M66457</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-03T18:14:18Z</dc:date>
    </item>
    <item>
      <title>Re: character question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309105#M66459</link>
      <description>&lt;P&gt;Thanks. I tried. It is powerful. However, I just listed two sequences above. Actually I have over 50 sequences to mark. Do you have any method to add conditions to deal with the data? Thanks&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 21:34:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309105#M66459</guid>
      <dc:creator>Niugg2010</dc:creator>
      <dc:date>2016-11-03T21:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: character question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309169#M66473</link>
      <description>&lt;PRE&gt;
It would be very convenient for SAS/IML , if you could post the output you want.
Or Post it at IML forum .

&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Nov 2016 02:51:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309169#M66473</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-04T02:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: character question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309181#M66477</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
length f1 $ 200;
input f1;
datalines;
GAGCAAGCGCCATACTCCTGTGGAGAAGTCTGCCGTTACTGCCCTGTGGGGCAAGGTGAACGTGGA
GAGCAAGCGCCATAGTCCTGTGGAGAAGTCTGCCGTTACTGCCCTGTGGGGCAAGGTGAACGTGGA
;
run;
proc format;
value fmt
 1='red';
run;

proc iml;
use a nobs nobs;
read all var {f1};
close;
n=length(f1)[1];
temp=j(nobs,n,' ');
do i=1 to nobs;
 temp[i,]=substr(f1[i],1:n,1);
end;
want=(countunique(temp,'col')&amp;gt;1);
create want from want;
append from want;
close;
run;
proc report data=want nowd;
define col:/style={backgroundcolor=fmt.};
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Nov 2016 04:39:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309181#M66477</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-04T04:39:46Z</dc:date>
    </item>
    <item>
      <title>Re: character question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309192#M66482</link>
      <description>&lt;P&gt;Use of SUBSTR() function can be replaced by the new function, COMPARE(). It will compare both the strings and will return the first leftmost POSITION where they differ. If you need to search more than one character-position, then you could compare() to the right of the position returned. The benefit is that you can skip those strings which are same.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Nov 2016 06:18:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309192#M66482</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2016-11-04T06:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: character question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309227#M66491</link>
      <description>&lt;P&gt;Cool. Thanks. Learn a lot. I have never used PROC IML.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Nov 2016 11:23:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309227#M66491</guid>
      <dc:creator>Niugg2010</dc:creator>
      <dc:date>2016-11-04T11:23:11Z</dc:date>
    </item>
    <item>
      <title>Re: character question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309228#M66492</link>
      <description>&lt;P&gt;I an not familar to compare() function. Can you help me to optimize my code with compare()? Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Nov 2016 11:24:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309228#M66492</guid>
      <dc:creator>Niugg2010</dc:creator>
      <dc:date>2016-11-04T11:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: character question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309246#M66498</link>
      <description>&lt;P&gt;OK.If you really want data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
length f1 $ 200;
input f1;
datalines;
GAGCAAGCGCCATACTCCTGTGGAGAAGTCTGCCGTTACTGCCCTGTGGGGCAAGGTGAACGTGGA
GAGCAAGCGCCATAGTCCTGTGGAGAAGTCTGCCGTTACTGCCCTGTGGGGCAAGGTGAACGTGGA
GAGCAAGCGCCATAGTCCTGTGGAGAAGTCTGCCGTTACTGCCCTGTGGGGCAAAGTGAACGTGGA
AAGCAAGCGCCATAGTCCTGTGGAGSAGTCTGCCGTTACTGCCCTGTGGGGCAAGGTGAACGTGGA
;
run;
proc format;
value fmt
 1='red';
run;
data _null_;
 set a;
 call symputx('n',length(f1));
 stop;
run;
data temp;
 set a;
 array x{&amp;amp;n} $ 1;
 do i=1 to &amp;amp;n;
  x{i}=char(f1,i);
 end;
 keep x:;
run;
proc transpose data=temp(obs=0) out=vnames;
var _all_;
run;
data _null_;
 set vnames end=last;
 if _n_=1 then call execute('proc sql;create table flag as select ');
 call execute(cat('count(distinct ',_name_,') as ',_name_));
 if last then call execute ('from temp;quit;');
  else call execute(',');
run;
proc transpose data=flag out=diff_temp;
var _all_;
run;
data diff_vname;
 set diff_temp;
 if col1 ne 1;
run;
data want;
if _n_=1 then do;
 if 0 then set diff_vname;
 declare hash h(dataset:'diff_vname');
 h.definekey('_name_');
 h.definedata('col1');
 h.definedone();
end;
call missing(of _all_);
 set vnames;
 rc=h.find();
run;
data _null_;
 set want end=last;
 if _n_=1 then call execute('proc report data=temp nowd;');
 call execute(cat('define ',_name_,'/display'));
 if not missing(col1) then call execute(' style={backgroundcolor=red}');
 call execute(';');
 if last then call execute('run;');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Nov 2016 13:13:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309246#M66498</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-04T13:13:41Z</dc:date>
    </item>
    <item>
      <title>Re: character question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309248#M66501</link>
      <description>&lt;P&gt;Thanks. I got it.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Nov 2016 13:19:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309248#M66501</guid>
      <dc:creator>Niugg2010</dc:creator>
      <dc:date>2016-11-04T13:19:52Z</dc:date>
    </item>
    <item>
      <title>Re: character question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309324#M66507</link>
      <description>&lt;P&gt;Compare() function compares two strings. Returns left-most position of the byte which is not matching and 0(zero) when the two strings are same. &amp;nbsp;Since you have given only two strings which has a differeing byte at the 15-position and I am adding one more string to show that COMPARE() function returns 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
length f1 $ 66;
input f1;
datalines;
GAGCAAGCGCCATACTCCTGTGGAGAAGTCTGCCGTTACTGCCCTGTGGGGCAAGGTGAACGTGGA
GAGCAAGCGCCATACTCCTGTGGAGAAGTCTGCCGTTACTGCCCTGTGGGGCAAGGTGAACGTGGA
GAGCAAGCGCCATAGTCCTGTGGAGAAGTCTGCCGTTACTGCCCTGTGGGGCAAGGTGAACGTGGA
;
run;

data _null_;
   retain old;

   set a;
   if _n_ = 1 then old = f1;
   else do;
      dif = compare(f1, old);
      put dif = ;
      if dif = 0 then put 'No Difference';
      if dif ^= 0 then substr(f1, dif, 1) = lowcase(substr(f1, dif, 1));
      put f1 = ;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Nov 2016 14:45:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/character-question/m-p/309324#M66507</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2016-11-04T14:45:20Z</dc:date>
    </item>
  </channel>
</rss>

