<?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: replace values ending with the same suffix with the variables with the other suffix in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/replace-values-ending-with-the-same-suffix-with-the-variables/m-p/544391#M150557</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/108652"&gt;@CHL0320&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;The order is all the variables ending with _LP first and then the ones with_HP later.&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If the ORDER between the _LP and _HP match then the code example I provided above should work. The first variable in each list would be the first (left most or lowest column&amp;nbsp;number from proc contents) and the last would the last (right most / largest column number) for each set of variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is absolutely no way we can show code with your variables if you don't share the names with us if that is what you are waiting for.&lt;/P&gt;</description>
    <pubDate>Tue, 19 Mar 2019 22:00:56 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-03-19T22:00:56Z</dc:date>
    <item>
      <title>replace values ending with the same suffix with the variables with the other suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-values-ending-with-the-same-suffix-with-the-variables/m-p/544301#M150516</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have variables ending either with _LP or _HP.&amp;nbsp; There are some observations need to be replaced their values in _LP (were missing) to the value in _HP.&amp;nbsp; For example, conditons_LP was missing and needs to be replaced with the value shown in conditions_HP. Any suggestions? Thank you so much.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2019 18:12:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-values-ending-with-the-same-suffix-with-the-variables/m-p/544301#M150516</guid>
      <dc:creator>CHL0320</dc:creator>
      <dc:date>2019-03-19T18:12:23Z</dc:date>
    </item>
    <item>
      <title>Re: replace values ending with the same suffix with the variables with the other suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-values-ending-with-the-same-suffix-with-the-variables/m-p/544304#M150518</link>
      <description>&lt;P&gt;How many variables share this suffix? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2019 18:17:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-values-ending-with-the-same-suffix-with-the-variables/m-p/544304#M150518</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-03-19T18:17:33Z</dc:date>
    </item>
    <item>
      <title>Re: replace values ending with the same suffix with the variables with the other suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-values-ending-with-the-same-suffix-with-the-variables/m-p/544307#M150520</link>
      <description>&lt;DIV class="yiv1263001157ydp9225b214yahoo-style-wrap"&gt;276 variables with the suffix ending with _LP and the other 276 variables with _HP. Plus one ID variable. There is a total of 553 variables so far.&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="yiv1263001157ydp9225b214yahoo-style-wrap"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="yiv1263001157ydp9225b214yahoo-style-wrap"&gt;Thank you.&lt;/DIV&gt;</description>
      <pubDate>Tue, 19 Mar 2019 18:24:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-values-ending-with-the-same-suffix-with-the-variables/m-p/544307#M150520</guid>
      <dc:creator>CHL0320</dc:creator>
      <dc:date>2019-03-19T18:24:57Z</dc:date>
    </item>
    <item>
      <title>Re: replace values ending with the same suffix with the variables with the other suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-values-ending-with-the-same-suffix-with-the-variables/m-p/544318#M150522</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/108652"&gt;@CHL0320&lt;/a&gt;&amp;nbsp; &amp;nbsp;Can you post a sample of the structure i.e some 5 vars&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;is it _LP...... series first followed by _HP or the order is random?&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2019 18:46:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-values-ending-with-the-same-suffix-with-the-variables/m-p/544318#M150522</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-19T18:46:47Z</dc:date>
    </item>
    <item>
      <title>Re: replace values ending with the same suffix with the variables with the other suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-values-ending-with-the-same-suffix-with-the-variables/m-p/544320#M150524</link>
      <description>&lt;P&gt;Tell us more about your data. Are the LP all adjacent in the data set? Meaning if you run proc contents the column numbers are in sequence? or if you look in a table are the column headers together? Is the order of the HP variables in the data set the same?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the variables of a common suffix are together &lt;STRONG&gt;and &lt;/STRONG&gt;the order of the base variable names is the same such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;var1_lp var2_lp var3_lp … var25_lp&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;other variables perhaps&amp;gt; var1_hp var2_hp var3_hp … var25_hp&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then something like this will work:&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   array l   var1_lp -- var25_lp;
   array h   var1_hp -- var25_hp;
   do i=1 to dim(l);
      if missing ( l[i]) then l[i] = h[i];
   end;
run;&lt;/PRE&gt;
&lt;P&gt;The key bit is to get the names of the matching variables in the array l and array h definitions to align exactly.&lt;/P&gt;
&lt;P&gt;If scattered or intermingled how much is needed to get a properly ordered list of the two sets of variables is where the work actually goes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the variable list using 2 dashes is for variables with adjoining or sequential columns and says to use all of the variables in the interval. The Array definition will fail if all of the variables are not of the same type. In which case we need a lot more information about the actual contents of the data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2019 18:52:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-values-ending-with-the-same-suffix-with-the-variables/m-p/544320#M150524</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-19T18:52:50Z</dc:date>
    </item>
    <item>
      <title>Re: replace values ending with the same suffix with the variables with the other suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-values-ending-with-the-same-suffix-with-the-variables/m-p/544326#M150527</link>
      <description>&lt;P&gt;&lt;SPAN&gt;The order is all the variables ending with _LP first and then the ones with_HP later.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2019 19:06:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-values-ending-with-the-same-suffix-with-the-variables/m-p/544326#M150527</guid>
      <dc:creator>CHL0320</dc:creator>
      <dc:date>2019-03-19T19:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: replace values ending with the same suffix with the variables with the other suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-values-ending-with-the-same-suffix-with-the-variables/m-p/544329#M150530</link>
      <description>&lt;P&gt;This might do, if your variables are numeric:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input a_lp a_hp b_lp b_hp c_lp;
datalines;
. 1 2 3 4
5 . . . .
. 6 . 7 8
;

proc sql;
select cats(name, "=coalesce(", name, ", ", substr(name,1,length(name)-3), "_hp)")
into :assign separated by "; "
from dictionary.columns 
where libname="WORK" and memname="HAVE" and trim(upcase(name)) like "%_LP";
quit;

data want;
set have;
&amp;amp;assign.;
run;

proc print data=want noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Mar 2019 19:09:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-values-ending-with-the-same-suffix-with-the-variables/m-p/544329#M150530</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-03-19T19:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: replace values ending with the same suffix with the variables with the other suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-values-ending-with-the-same-suffix-with-the-variables/m-p/544391#M150557</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/108652"&gt;@CHL0320&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;The order is all the variables ending with _LP first and then the ones with_HP later.&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If the ORDER between the _LP and _HP match then the code example I provided above should work. The first variable in each list would be the first (left most or lowest column&amp;nbsp;number from proc contents) and the last would the last (right most / largest column number) for each set of variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is absolutely no way we can show code with your variables if you don't share the names with us if that is what you are waiting for.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Mar 2019 22:00:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-values-ending-with-the-same-suffix-with-the-variables/m-p/544391#M150557</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-19T22:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: replace values ending with the same suffix with the variables with the other suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/replace-values-ending-with-the-same-suffix-with-the-variables/m-p/544439#M150566</link>
      <description>&lt;P&gt;You should probably use metadata to generate the code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=have noprint out=contents; run;
proc sql noprint;
create table pairs as 
select a.name as LP
     , b.name as HP
from contents a 
inner join contents b
on upcase(substr(a.name,length(a.name)-2))
 = upcase(substr(b.name,length(b.name)-2))
and upcase(a.name) like '%^_LP' escape '^'
and upcase(b.name) like '%^_HP'  escape '^'
order by a.varnum
;
select lp,hp into :lp separated by ' ', :hp separated by ' '
from pairs
;
quit;
data want ;
  set have;
  array lp &amp;amp;lp;
  array hp &amp;amp;hp;
  do i=1 to dim(lp);
    lp(i)=coalesce(lp(i),hp(i));
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 Mar 2019 04:36:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/replace-values-ending-with-the-same-suffix-with-the-variables/m-p/544439#M150566</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-03-20T04:36:13Z</dc:date>
    </item>
  </channel>
</rss>

