<?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: Extract value from a column based on other columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-value-from-a-column-based-on-other-columns/m-p/455031#M115058</link>
    <description>&lt;P&gt;It almost makes sense to me &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;P&gt;Please post an example og´f the other table and what you want the result to look like.&lt;/P&gt;</description>
    <pubDate>Wed, 18 Apr 2018 05:44:03 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2018-04-18T05:44:03Z</dc:date>
    <item>
      <title>Extract value from a column based on other columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-value-from-a-column-based-on-other-columns/m-p/455030#M115057</link>
      <description>&lt;P&gt;A quick question&lt;/P&gt;
&lt;P&gt;I am tying to join 2 tables using:&lt;/P&gt;
&lt;P&gt;The first table is ICD10s:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ICD10;
input Group:$ L1:$ L2:$ L3:$ ;
datalines;
1 F70 E16 G12
2 F71 E17 .
3 F72 E18 H4
4 F73 E19 .
5 F74 E76 .

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The second table has patient names and their ICD10 code&lt;/P&gt;
&lt;P&gt;What I am trying to achieve is to get the group number from the table above based on the matched ICD codes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Say that a patient has an ICD code of E17, then I need the combined table to contain the patient's name and group "2" extracted from the table above&lt;/P&gt;
&lt;P&gt;If the patient has ICD of G12 then the column should have the group number 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How could this be achieved please? The problem here is that I dont know beforehand how many rows and columns the ICD table above will contain, so it needs to be a "generic" code...&lt;/P&gt;
&lt;P&gt;Apologies if I am not making sense here!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 05:39:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-value-from-a-column-based-on-other-columns/m-p/455030#M115057</guid>
      <dc:creator>ammarhm</dc:creator>
      <dc:date>2018-04-18T05:39:52Z</dc:date>
    </item>
    <item>
      <title>Re: Extract value from a column based on other columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-value-from-a-column-based-on-other-columns/m-p/455031#M115058</link>
      <description>&lt;P&gt;It almost makes sense to me &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;P&gt;Please post an example og´f the other table and what you want the result to look like.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 05:44:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-value-from-a-column-based-on-other-columns/m-p/455031#M115058</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-04-18T05:44:03Z</dc:date>
    </item>
    <item>
      <title>Re: Extract value from a column based on other columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-value-from-a-column-based-on-other-columns/m-p/455044#M115060</link>
      <description>&lt;P&gt;Transpose your icd10 dataset, so you can easily join:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ICD10;
input Group:$ L1:$ L2:$ L3:$ ;
datalines;
1 F70 E16 G12
2 F71 E17 .
3 F72 E18 H4
4 F73 E19 .
5 F74 E76 .
;
run;

proc transpose
  data=icd10
  out=icd_trans (
    drop=_name_
    rename=(col1=icd10)
    where=(icd10 ne ' ')
  )
;
by group;
var l:;
run;

proc sort data=icd_trans;
by icd10;
run;

data want;
merge
  icd_trans (in=a)
  patients (in=b)
;
by icd10;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(assuming that patients has the required variables and is sorted accordingly)&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 06:43:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-value-from-a-column-based-on-other-columns/m-p/455044#M115060</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-18T06:43:01Z</dc:date>
    </item>
    <item>
      <title>Re: Extract value from a column based on other columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-value-from-a-column-based-on-other-columns/m-p/455068#M115072</link>
      <description>&lt;P&gt;I would recommend creating a format from your ICD10 data set.&amp;nbsp; That way, you won't need to sort your patient data.&amp;nbsp; In fact, patient data often contains multiple ICD10 codes per observation and wouldn't be suitable for sorting without jumping through major hoops. At any rate:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data reshape;&lt;/P&gt;
&lt;P&gt;set icd10 end=done;&lt;/P&gt;
&lt;P&gt;retain fmtname '$group';&lt;/P&gt;
&lt;P&gt;array icds {3} L1-L3;&lt;/P&gt;
&lt;P&gt;label = group;&lt;/P&gt;
&lt;P&gt;do k=1 to 3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if icds{k} &amp;gt; ' ' then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; start = icds{k};&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;end;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;if done;&lt;/P&gt;
&lt;P&gt;label = ' ';&lt;/P&gt;
&lt;P&gt;hlo='O';&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do need to know the maximum number of codes that can appear in one group, since that is hard-coded here at 3.&amp;nbsp; That piece can be automated but it takes a little work to do that.&amp;nbsp; This gives you a data set that PROC FORMAT can consume, creating a format named $group:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc format cntlin=reshape;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All that is left to do is apply that format:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;group = put(ICD10, $group.);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 09:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-value-from-a-column-based-on-other-columns/m-p/455068#M115072</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-18T09:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: Extract value from a column based on other columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-value-from-a-column-based-on-other-columns/m-p/455122#M115103</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;I have to say I am very impressed by the solution you suggested using proc format. I like the simplicity yet lateral thinking approach here.&lt;/P&gt;
&lt;P&gt;Could you please elaborate on how to automate the maximun number of ICD columns (in the example i gave there were 3 columns and you created and array:&amp;nbsp;&lt;SPAN&gt;array icds {3} L1-L3;) is there a way to expand this code so that it could account for any number of columns in the ICD10 table I had at the beginning&amp;nbsp;of the example?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 12:25:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-value-from-a-column-based-on-other-columns/m-p/455122#M115103</guid>
      <dc:creator>ammarhm</dc:creator>
      <dc:date>2018-04-18T12:25:28Z</dc:date>
    </item>
    <item>
      <title>Re: Extract value from a column based on other columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-value-from-a-column-based-on-other-columns/m-p/455124#M115104</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/24798"&gt;@ammarhm&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&lt;/P&gt;
&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;is there a way to expand this code so that it could account for any number of columns in the ICD10 table I had at the beginning&amp;nbsp;of the example?&lt;/SPAN&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;See my proc transpose example. It takes care of an arbitrary number of columns, as long as they start with an L. It's always better to work with a long vs. a wide dataset layout.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 12:36:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-value-from-a-column-based-on-other-columns/m-p/455124#M115104</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-18T12:36:59Z</dc:date>
    </item>
    <item>
      <title>Re: Extract value from a column based on other columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-value-from-a-column-based-on-other-columns/m-p/455125#M115105</link>
      <description>&lt;P&gt;We really have to back up here.&amp;nbsp; How did you know that your INPUT statement should input L3 but shouldn't try to input L4?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are certain the ICD10 data set will contain only variables named GROUP, plus L1, L2, L3, ..., Ln, it's an easy change to the existing code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, the ARRAY statement becomes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array icds {*} L:;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Secondly, the DO loop becomes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do k=1 to dim(icds);&lt;/P&gt;</description>
      <pubDate>Wed, 18 Apr 2018 12:41:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-value-from-a-column-based-on-other-columns/m-p/455125#M115105</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-18T12:41:32Z</dc:date>
    </item>
  </channel>
</rss>

