<?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 create a table compsed out of 2 translating tables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-table-compsed-out-of-2-translating-tables/m-p/830976#M328364</link>
    <description>&lt;P&gt;The ask does not make any sense.&lt;/P&gt;
&lt;P&gt;What the heck is B$1 and B$2 supposed to be?&lt;/P&gt;
&lt;P&gt;Is that supposed to look like Excel notation?&amp;nbsp; So B refers to a column in a spreadsheet and 1 and 2 rows in the column?&lt;/P&gt;
&lt;P&gt;To lookup values in a dataset you need to have a key variable for the dataset.&amp;nbsp; Is that what this means?&amp;nbsp; If so then why the heck would you want to divide the value in the second row by the value in the first row?&amp;nbsp; What meaning would that have?&lt;/P&gt;</description>
    <pubDate>Mon, 29 Aug 2022 18:55:52 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-08-29T18:55:52Z</dc:date>
    <item>
      <title>How to create a table compsed out of 2 translating tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-table-compsed-out-of-2-translating-tables/m-p/830865#M328320</link>
      <description>&lt;P&gt;What is the best way to create table C_Want from A_Have and B_Have ?&lt;/P&gt;&lt;P&gt;ALl tables are long - this is only an example.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Data A_Have ;&lt;BR /&gt;INPUT NUM_A $CHAR2. Ser $CHAR20. ;&lt;BR /&gt;cards ;&lt;BR /&gt;A2 B$1&lt;BR /&gt;A3 B$2&lt;BR /&gt;A4 B$3&lt;BR /&gt;A5 B$4&lt;BR /&gt;;&lt;BR /&gt;Run ;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Data B_Have ;&lt;BR /&gt;INPUT NUM_B $CHAR2. Formula $CHAR20. ;&lt;BR /&gt;cards ;&lt;BR /&gt;B2 A2 / A3&lt;BR /&gt;B3 A4 / A5&lt;BR /&gt;;&lt;BR /&gt;Run ;&lt;/P&gt;&lt;P&gt;Data C_Want ;&lt;BR /&gt;INPUT NUM_B $CHAR2. Formula $CHAR20. ;&lt;BR /&gt;cards ;&lt;BR /&gt;B2 B$1 / B$2&lt;BR /&gt;B3 B$3 / B$4&lt;BR /&gt;;&lt;BR /&gt;Run ;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2022 10:31:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-table-compsed-out-of-2-translating-tables/m-p/830865#M328320</guid>
      <dc:creator>J111</dc:creator>
      <dc:date>2022-08-29T10:31:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a table compsed out of 2 translating tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-table-compsed-out-of-2-translating-tables/m-p/830868#M328322</link>
      <description>&lt;P&gt;If there is some logic behind these values (that smell of Excel formula's &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; )? I would rather implement that logic instead of going through many predictable rows in tables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That said, If there is not, I would code a data step that reads B_Have, loads A_Have in &lt;A href="https://support.sas.com/resources/papers/proceedings17/0821-2017.pdf" target="_self"&gt;a hash table&lt;/A&gt; and perform lookups on that hash table that would map A2 to B$1 etc. I can provide a code example but would have to know first what you mean by "long"? Thousands of rows, milions, ...?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;- Jan&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2022 11:53:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-table-compsed-out-of-2-translating-tables/m-p/830868#M328322</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2022-08-29T11:53:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a table compsed out of 2 translating tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-table-compsed-out-of-2-translating-tables/m-p/830873#M328323</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;"Long" meaning hundreds and not only 2 obs.&lt;/P&gt;&lt;P&gt;A code would be wonderful. Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2022 12:02:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-table-compsed-out-of-2-translating-tables/m-p/830873#M328323</guid>
      <dc:creator>J111</dc:creator>
      <dc:date>2022-08-29T12:02:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a table compsed out of 2 translating tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-table-compsed-out-of-2-translating-tables/m-p/830877#M328325</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data A_Have ;
INPUT NUM_A $CHAR2. Ser $CHAR20. ;
cards ;
A2 B$1
A3 B$2
A4 B$3
A5 B$4
;
Run ;


Data B_Have ;
INPUT NUM_B $CHAR2. Formula $CHAR20. ;
cards ;
B2 A2 / A3
B3 A4 / A5
;
Run ;

data format;
 set a_have(rename=(num_a=start ser=label));
 retain fmtname 'fmt' type 'c';
run;
proc format cntlin=format;
run;
data want;
 set b_have(rename=(Formula=_f));
 length formula $ 40;
 do i=1 to countw(_f,'/ '); 
  formula=catx(' / ',formula,put(scan(_f,i,'/ '),$fmt.));
 end;
 drop i _f;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Aug 2022 12:18:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-table-compsed-out-of-2-translating-tables/m-p/830877#M328325</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-08-29T12:18:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a table compsed out of 2 translating tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-table-compsed-out-of-2-translating-tables/m-p/830882#M328328</link>
      <description>&lt;P&gt;There is &lt;U&gt;no logic&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Just general sequence of 2 variables:-&lt;/P&gt;&lt;P&gt;A(I) and&amp;nbsp;B(J), For&amp;nbsp; example&lt;/P&gt;&lt;P&gt;I = 1,2,3...&amp;nbsp; and J = 7,8,9...&lt;/P&gt;&lt;P&gt;B$(K) For any K&amp;nbsp; For example K= 11108&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks !&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2022 12:51:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-table-compsed-out-of-2-translating-tables/m-p/830882#M328328</guid>
      <dc:creator>J111</dc:creator>
      <dc:date>2022-08-29T12:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a table compsed out of 2 translating tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-table-compsed-out-of-2-translating-tables/m-p/830956#M328361</link>
      <description>&lt;P&gt;Thanks - One more detail to solve:- the formula could have more seperators&amp;nbsp; such as (+ * / -)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Data B_Have ;&lt;BR /&gt;INPUT NUM_B $CHAR2. Formula $CHAR30. ;&lt;BR /&gt;cards ;&lt;BR /&gt;B2 A2 / (A3 + A4) * 2&lt;BR /&gt;B3 A4 / (A5 - A2)&lt;BR /&gt;;&lt;BR /&gt;Run ;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2022 17:43:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-table-compsed-out-of-2-translating-tables/m-p/830956#M328361</guid>
      <dc:creator>J111</dc:creator>
      <dc:date>2022-08-29T17:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a table compsed out of 2 translating tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-table-compsed-out-of-2-translating-tables/m-p/830976#M328364</link>
      <description>&lt;P&gt;The ask does not make any sense.&lt;/P&gt;
&lt;P&gt;What the heck is B$1 and B$2 supposed to be?&lt;/P&gt;
&lt;P&gt;Is that supposed to look like Excel notation?&amp;nbsp; So B refers to a column in a spreadsheet and 1 and 2 rows in the column?&lt;/P&gt;
&lt;P&gt;To lookup values in a dataset you need to have a key variable for the dataset.&amp;nbsp; Is that what this means?&amp;nbsp; If so then why the heck would you want to divide the value in the second row by the value in the first row?&amp;nbsp; What meaning would that have?&lt;/P&gt;</description>
      <pubDate>Mon, 29 Aug 2022 18:55:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-table-compsed-out-of-2-translating-tables/m-p/830976#M328364</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-29T18:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a table compsed out of 2 translating tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-table-compsed-out-of-2-translating-tables/m-p/830984#M328367</link>
      <description>&lt;P&gt;Sounds like you want replace the string A2 with the string B$1.&lt;/P&gt;
&lt;P&gt;If the values are always one letter followed by one digit then TRANWRD() could do that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length formula $30;
formula = 'A2 / A3';
formula = tranwrd(formula,'A2','B$1');
formula = tranwrd(formula,'A3','B$2');
...
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the values could be a letter followed by more than one digit.&amp;nbsp; Like A1, A2, ... A9, A10, A11 etc then you would need to do them in reverse order so that the A10 and A11 are replaced before the attempt to replace A1 happens.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;formula = tranwrd(formula,'A11','B$10');
formula = tranwrd(formula,'A10','B$9');
...
formula = tranwrd(formula,'A1','B$0');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If it more complex then you will need to use regular expressions instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you work out what code will make the changes implied by HAVE1 then it just reduces to a code generation step of using the data in HAVE1 to generate the code needed to modify HAVE2.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have1 ;
  by descending num_a;
run;

filename code temp;
data _null_;
  file code;
  set have1;
  by descending NUM_A;
  put 'formula=tranwrd(formula,' num_a :$quote. ',' ser :$quote. ');' ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And then using the generated code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  length num_b $2 formula $50 ;
  set have2;
%include code / source2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;OBS    num_b     formula

 1      B2      B$1 / B$2
 2      B3      B$3 / B$4
&lt;/PRE&gt;
&lt;P&gt;Test:&lt;/P&gt;
&lt;PRE&gt;Observation Summary                                                                                                                 
                                                                                                                                    
Observation      Base  Compare                                                                                                      
                                                                                                                                    
First Obs           1        1                                                                                                      
Last  Obs           2        2                                                                                                      
                                                                                                                                    
Number of Observations in Common: 2.                                                                                                
Total Number of Observations Read from WORK.EXPECT: 2.                                                                              
Total Number of Observations Read from WORK.WANT: 2.                                                                                
                                                                                                                                    
Number of Observations with Some Compared Variables Unequal: 0.                                                                     
Number of Observations with All Compared Variables Equal: 2.                                                                        
                                                                                                                                    
NOTE: No unequal values were found.                      &lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Aug 2022 19:26:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-table-compsed-out-of-2-translating-tables/m-p/830984#M328367</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-29T19:26:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to create a table compsed out of 2 translating tables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-table-compsed-out-of-2-translating-tables/m-p/831045#M328395</link>
      <description>&lt;P&gt;Thanks for all the answers, I appreciate your time very much !&lt;/P&gt;</description>
      <pubDate>Tue, 30 Aug 2022 07:34:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-a-table-compsed-out-of-2-translating-tables/m-p/831045#M328395</guid>
      <dc:creator>J111</dc:creator>
      <dc:date>2022-08-30T07:34:47Z</dc:date>
    </item>
  </channel>
</rss>

