<?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: compress and upcase  in Merge in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/compress-and-upcase-in-Merge/m-p/981962#M379214</link>
    <description>&lt;P&gt;Looks like you are trying to standardize the variable names so they will match.&lt;/P&gt;
&lt;P&gt;You might want to add a new variable to each dataset with the standardized variable name.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;uname=upcase(compress(var_name));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can sort and/or merge by that new variable but still have the mixed case value for making pretty printouts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Jan 2026 16:04:37 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2026-01-14T16:04:37Z</dc:date>
    <item>
      <title>compress and upcase  in Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compress-and-upcase-in-Merge/m-p/981932#M379206</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;When I run following query the merge perform 100%&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table t5_Long_c as
select a.*,b.Theur_VAR_NAME,b.Theur_CATEGORY,b.Regression_Coefficient
from t5_Long_b as a
left join r_r.Derug_AP_Decoding_tbl  as b
on compress(upcase(a.Var_name))=compress(upcase(b.Var_name))  and a.Category=b.Category
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, when I run this code it doesn't success find matching rows.&lt;/P&gt;
&lt;P&gt;It probably happend because in proc sql I used compress and upcase (for matching char var) and in data set (merge) I couldnt do it.&lt;/P&gt;
&lt;P&gt;My question-&lt;/P&gt;
&lt;P&gt;Is there a way to add&amp;nbsp;compress and upcase&amp;nbsp; to merge via data set (merge)?&lt;/P&gt;
&lt;P&gt;I know I can do it before (In each data set define a new var using&amp;nbsp;compress and upcase )&lt;/P&gt;
&lt;P&gt;But my question if it can be done directly in merge ??&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=r_r.Derug_AP_Decoding_tbl;
by Var_name CATEGORY;
Run;

proc sort data=t5_Long_b;
by Var_name CATEGORY;
Run;

data t5_Long_c;
merge t5_Long_b(in=a)  r_r.Derug_AP_Decoding_tbl;
by Var_name CATEGORY;
if a;
Run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Jan 2026 05:40:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compress-and-upcase-in-Merge/m-p/981932#M379206</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2026-01-14T05:40:17Z</dc:date>
    </item>
    <item>
      <title>Re: compress and upcase  in Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compress-and-upcase-in-Merge/m-p/981933#M379207</link>
      <description>First of all, you should do such data cleaning immediately when the data is read into the SAS environment in the first place.&lt;BR /&gt;&lt;BR /&gt;You can define DATA step or SQL views (DATA preferred) that do the conversion, and use these in the MERGE.</description>
      <pubDate>Wed, 14 Jan 2026 08:11:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compress-and-upcase-in-Merge/m-p/981933#M379207</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2026-01-14T08:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: compress and upcase  in Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compress-and-upcase-in-Merge/m-p/981946#M379209</link>
      <description>&lt;P&gt;No, you cannot do it in the MERGE step.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The MERGE statement reads the key values from each dataset, then decides which record(s) to read into the PDV.&amp;nbsp; &amp;nbsp;You cannot use an expression on the BY statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was going to write that it's not possible to modify the key value before it is read by the&amp;nbsp; BY statement, because the data would need to be read into the PDV first.&amp;nbsp; &amp;nbsp;But the WHERE statement is happy to modify key values before they are read into the PDV, so you can do stuff like: where upcase(category)='FOO'.&amp;nbsp; So theoretically the BY statement could allow you to manipulate the key values before they are compared.&amp;nbsp; But I don't think we're likely to see that added as a new feature.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jan 2026 14:12:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compress-and-upcase-in-Merge/m-p/981946#M379209</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2026-01-14T14:12:09Z</dc:date>
    </item>
    <item>
      <title>Re: compress and upcase  in Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compress-and-upcase-in-Merge/m-p/981962#M379214</link>
      <description>&lt;P&gt;Looks like you are trying to standardize the variable names so they will match.&lt;/P&gt;
&lt;P&gt;You might want to add a new variable to each dataset with the standardized variable name.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;uname=upcase(compress(var_name));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can sort and/or merge by that new variable but still have the mixed case value for making pretty printouts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jan 2026 16:04:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compress-and-upcase-in-Merge/m-p/981962#M379214</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-01-14T16:04:37Z</dc:date>
    </item>
    <item>
      <title>Re: compress and upcase  in Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compress-and-upcase-in-Merge/m-p/981968#M379216</link>
      <description>&lt;P&gt;Just for fun. In some cases you can &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
PROC FCMP outlib=WORK.F.P;
  function UPCASECOMPRESS(s$)$32767;
    return(UPCASE(COMPRESS(s)));
  endfunc;
QUIT;

options append=(cmplib=WORK.F);

proc format;
value $ UPCASECOMPRESS
other=[UPCASECOMPRESS()]
;
run;

data have1;
  infile cards dlm=",";
  input Var_name $ CATEGORY $;
  data1+1;
cards;
 A b ,x
BC ,Y
 ab, X
aB ,X
 bc, y
b C, y
;
run;
title "vanila have1";
proc print data=have1;
run;

data have2;
  infile cards dlm=",";
  input Var_name $ CATEGORY $;
  data2+10;
cards;
ab, x
 Bc, Y
C D, Z
;
run;
title "vanila have2";
proc print data=have2;
run;


proc datasets nolist lib=work;
modify have1;
  format Var_name CATEGORY $UPCASECOMPRESS.;
run;
modify have2;
  format Var_name CATEGORY $UPCASECOMPRESS.;
run;
quit;

proc sort data=have1 sortseq=linguistic(locale=PL_PL); /* sorts: AaBbCcDd... */
by Var_name CATEGORY;
run;
title "sorted and formatted have1";
proc print data=have1;
run;

proc sort data=have2 sortseq=linguistic(locale=PL_PL);
by Var_name CATEGORY;
run;
title "sorted and formatted have2";
proc print data=have2;
run;

data WANT;
merge have1 have2;
by Var_name CATEGORY GROUPFORMAT;
run;
title "want";
proc print data=want;
run;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Output:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="yabwon_0-1768408931905.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/112624i75FD8A86E2DCC1CF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="yabwon_0-1768408931905.png" alt="yabwon_0-1768408931905.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jan 2026 16:43:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compress-and-upcase-in-Merge/m-p/981968#M379216</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2026-01-14T16:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: compress and upcase  in Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compress-and-upcase-in-Merge/m-p/981971#M379217</link>
      <description>&lt;P&gt;Amazing&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;, so creative, as always!&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jan 2026 17:03:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compress-and-upcase-in-Merge/m-p/981971#M379217</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2026-01-14T17:03:27Z</dc:date>
    </item>
    <item>
      <title>Re: compress and upcase  in Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compress-and-upcase-in-Merge/m-p/981986#M379219</link>
      <description>&lt;P&gt;You do no mention how many unique combinations of the variables Var_name and Category might have in the two data sets. MERGE behaves quite differently than SQL in the presence of more than one observation with the same values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In general I refrain from calling any SQL join a "merge" operation because I learned SAS data step code before any SQL and the data step Merge often behaves differently than any of the joins.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jan 2026 19:46:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compress-and-upcase-in-Merge/m-p/981986#M379219</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2026-01-14T19:46:46Z</dc:date>
    </item>
    <item>
      <title>Re: compress and upcase  in Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compress-and-upcase-in-Merge/m-p/981988#M379220</link>
      <description>&lt;P&gt;But as I wrote, Just for fun.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In fact the sorting is very reason why implementing request of adding functions to merging is not "doable" in general case. Sorted data (ready for MERGE) after applying a function can be not MERGEble anymore.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In fact my example is breaks for that reason,&lt;/P&gt;
&lt;P&gt;It's data dependent, so when you change data to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
  infile cards dlm=",";
  input Var_name $ CATEGORY $;
  data1+1;
cards;
A b ,x
 BC ,Y
ab, X
aB ,X
 bc, x
b C, y
 D e, X
D e, x
;
run;
title "vanila have1";
proc print data=have1;
run;

data have2;
  infile cards dlm=",";
  input Var_name $ CATEGORY $;
  data2+10;
cards;
ab, x
 Bc, Y
C D, Z
;
run;
title "vanila have2";
proc print data=have2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And you run the code (from previous post), result is:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="yabwon_0-1768419761920.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/112629i90CDD02A4982F49B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="yabwon_0-1768419761920.png" alt="yabwon_0-1768419761920.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;While it should be:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="yabwon_1-1768419783909.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/112630i7BFB2B8BC5085559/image-size/medium?v=v2&amp;amp;px=400" role="button" title="yabwon_1-1768419783909.png" alt="yabwon_1-1768419783909.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think, it can't be safely used for more than one merging variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let by=Var_name;
 
PROC FCMP outlib=WORK.F.P;
  function UPCASECOMPRESS(s$)$32767;
    return(UPCASE(COMPRESS(s)));
  endfunc;
QUIT;

options append=(cmplib=WORK.F);

proc format;
value $ UPCASECOMPRESS
other=[UPCASECOMPRESS()]
;
run;

data have1;
  infile cards dlm=",";
  input Var_name $ CATEGORY $;
  data1+1;
cards;
A b ,x
 BC ,Y
ab, X
aB ,X
 bc, x
b C, y
 D e, X
D e, x
;
run;
title "vanila have1";
proc print data=have1;
run;

data have2;
  infile cards dlm=",";
  input Var_name $ CATEGORY $;
  data2+10;
cards;
ab, x
 Bc, Y
C D, Z
;
run;
title "vanila have2";
proc print data=have2;
run;




proc sort data=have1 sortseq=linguistic(locale=PL_PL);
by &amp;amp;by.;
run;
title "sorted and formatted have1";
proc print data=have1;
run;

proc sort data=have2 sortseq=linguistic(locale=PL_PL);
by &amp;amp;by.;
run;
title "sorted and formatted have2";
proc print data=have2;
run;



proc datasets nolist lib=work;
modify have1;
  format Var_name CATEGORY $UPCASECOMPRESS.;
run;
modify have2;
  format Var_name CATEGORY $UPCASECOMPRESS.;
run;
quit;





data WANT;
merge have1(keep=&amp;amp;by. data:) have2(keep=&amp;amp;by. data:);
by &amp;amp;by.  GROUPFORMAT;
run;
title "want1";
proc print data=want;
run;

data have1b;
set have1;
format Var_name CATEGORY;
Var_name=UPCASE(COMPRESS(Var_name));
CATEGORY = UPCASE(COMPRESS(CATEGORY));
run;

data have2b;
set have2;
format Var_name CATEGORY;
Var_name=UPCASE(COMPRESS(Var_name));
CATEGORY = UPCASE(COMPRESS(CATEGORY));
run;

proc sort data=have1b sortseq=linguistic(locale=PL_PL);
by &amp;amp;by.;
run;
proc sort data=have2b sortseq=linguistic(locale=PL_PL);
by &amp;amp;by.;
run;

data WANT2;
merge have1b(keep=&amp;amp;by. data:) have2b(keep=&amp;amp;by. data:);
by &amp;amp;by.;
run;
title "want expected";
proc print data=want2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="yabwon_2-1768420265448.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/112631i87C06AAA8653FAD6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="yabwon_2-1768420265448.png" alt="yabwon_2-1768420265448.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now I'm looking how to break it even for 1 variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jan 2026 19:57:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compress-and-upcase-in-Merge/m-p/981988#M379220</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2026-01-14T19:57:20Z</dc:date>
    </item>
    <item>
      <title>Re: compress and upcase  in Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compress-and-upcase-in-Merge/m-p/981989#M379221</link>
      <description>&lt;P&gt;OK, so it's even more limited.&lt;/P&gt;
&lt;P&gt;I didn't notice that, because I was reading dataliens and values were adjusted left.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there are leading spaces the order is different, e.g. "&amp;lt;space&amp;gt;B" is sorted before "A".&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Further more, "A&amp;lt;space&amp;gt;C" is sorted before "AB" and "AC". So ordering of&amp;nbsp;"A&amp;lt;space&amp;gt;C", "AB", and "AC" won't give proper result since upcase+compressed is: "AB", "AC", "AC".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So in fact if there are spaces inside they break it too.&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>Wed, 14 Jan 2026 20:23:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compress-and-upcase-in-Merge/m-p/981989#M379221</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2026-01-14T20:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: compress and upcase  in Merge</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compress-and-upcase-in-Merge/m-p/981990#M379222</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;In fact the sorting is very reason why implementing request of adding functions to merging is not "doable" in general case. Sorted data (ready for MERGE) after applying a function can be not MERGEble anymore.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Ahh, that makes sense.&amp;nbsp; Definitely not implementable in MERGE. Thanks again.&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jan 2026 20:29:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compress-and-upcase-in-Merge/m-p/981990#M379222</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2026-01-14T20:29:06Z</dc:date>
    </item>
  </channel>
</rss>

