<?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: Extracting data from several columns to a column using separate dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extracting-data-from-several-columns-to-a-column-using-separate/m-p/837370#M331075</link>
    <description>&lt;P&gt;Please see attached as an example:&amp;nbsp;&lt;/P&gt;&lt;P&gt;*patient_id is not unique, so patient 1 from facility 123 is not the same as the patient 1 from facility 234.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 07 Oct 2022 19:12:04 GMT</pubDate>
    <dc:creator>orchid_sugar</dc:creator>
    <dc:date>2022-10-07T19:12:04Z</dc:date>
    <item>
      <title>Extracting data from several columns to a column using separate dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-data-from-several-columns-to-a-column-using-separate/m-p/837351#M331064</link>
      <description>&lt;P&gt;Dataset A has total of 51 numeric and character variables: facility_ID (num), procedure_code0 - procedure_code 24 (char), procedure_date0 - procedure_date24 (num).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dataset B has only 2 character variables: code (which is same as procedure_code0... not every value in procedure_code0 etc is in the dataset B 'code') and another_code (I need to translate to).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My goal is to extract the procedure_code and procedure_date based on the dataset B, so the final dataset will only have 3 columns/variables: facility ID, procedure_code_extracted, procedure_date_extracted.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My pseudocode came out as below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA extracted;&lt;/P&gt;&lt;P&gt;SET dataset A;&lt;/P&gt;&lt;P&gt;ARRAY procedure_Code (25) procedure_code0 - procedure_code 24;&lt;/P&gt;&lt;P&gt;DO i = 1 To 25;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; IF procedure_Code(i) = database B's code THEN procedure_code_extracted = procedureCode(i)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; also get the location of that matched procedureCode(i) [row, column]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; use that location to find procedure_date from procedure_date0 - procedure_date24 and input under&amp;nbsp;procedure_date_extracted&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if there is several matches in a row, make a new line for the subsequent match and repeat&lt;/P&gt;&lt;P&gt;End;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure how to make this logic into actual running SAS code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 11:06:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-data-from-several-columns-to-a-column-using-separate/m-p/837351#M331064</guid>
      <dc:creator>orchid_sugar</dc:creator>
      <dc:date>2022-10-07T11:06:22Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting data from several columns to a column using separate dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-data-from-several-columns-to-a-column-using-separate/m-p/837358#M331068</link>
      <description>&lt;P&gt;Could you please provide small example data sets — let's say 2 facilities and 3 procedure_codes and 3 procedure_dates in data set A, and the corresponding data set B? We would also need to see the desired output from this small example data.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 11:37:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-data-from-several-columns-to-a-column-using-separate/m-p/837358#M331068</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-10-07T11:37:01Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting data from several columns to a column using separate dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-data-from-several-columns-to-a-column-using-separate/m-p/837368#M331074</link>
      <description>&lt;P&gt;Sounds like you want to transpose A and then join/merge it with B.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a_wide;
  set a;
  array p procedure_code0-procedure_code24;
  array d procedure_date0-procedure_date24;
  do index=1 to dim(p);
     procedure_code = p[index];
     procedure_date = d[index];
     if not missing(procedure_code) then output;
  end;
  drop procedure_code0-procedure_code24 procedure_date0-procedure_date24;
run;

proc sort;
  by procedure_code;
run;

data want;
  merge a_wide (in=in1) b(in=in2);
  by procedure_code;
  if in1 and in2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you wanted to use your proposed DO loop instead then I would suggest converting B into a FORMAT that converts procedure_code into the value of the other variable in B.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 12:23:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-data-from-several-columns-to-a-column-using-separate/m-p/837368#M331074</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-10-07T12:23:56Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting data from several columns to a column using separate dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-data-from-several-columns-to-a-column-using-separate/m-p/837370#M331075</link>
      <description>&lt;P&gt;Please see attached as an example:&amp;nbsp;&lt;/P&gt;&lt;P&gt;*patient_id is not unique, so patient 1 from facility 123 is not the same as the patient 1 from facility 234.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 19:12:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-data-from-several-columns-to-a-column-using-separate/m-p/837370#M331075</guid>
      <dc:creator>orchid_sugar</dc:creator>
      <dc:date>2022-10-07T19:12:04Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting data from several columns to a column using separate dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-data-from-several-columns-to-a-column-using-separate/m-p/837371#M331076</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/435788"&gt;@orchid_sugar&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Please see attached as an example:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*patient_id is not unique, so patient 1 from facility 123 is not the same as the patient 1 from facility 234.&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;I think&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;has the answer ... but if that's not the right answer, please understand that we cannot use data in Excel. In addition, downloading Excel files (or any Microsoft Office files) is a security threat, so many people will not download Excel files. Please type (a portion of) the data into your reply.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2022 12:49:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-data-from-several-columns-to-a-column-using-separate/m-p/837371#M331076</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-10-07T12:49:07Z</dc:date>
    </item>
  </channel>
</rss>

