<?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: Proc transpose for Excel file with two rows for headers in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-transpose-for-Excel-file-with-two-rows-for-headers/m-p/843197#M333370</link>
    <description>Take your first two rows into a separate data set. Transpose it to a long format. Create new variable names that have the date and measure, ie SBP_2022_04 &lt;BR /&gt;Rename the variables in the file. Then transpose it.&lt;BR /&gt;&lt;BR /&gt;If you can trust that it's always SBP, DBP, TI in that order you can simplify this a bit but I'm not a trusting person when it comes to badly formatted data.</description>
    <pubDate>Tue, 08 Nov 2022 17:43:47 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2022-11-08T17:43:47Z</dc:date>
    <item>
      <title>Proc transpose for Excel file with two rows for headers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-transpose-for-Excel-file-with-two-rows-for-headers/m-p/843191#M333368</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to use Proc Transpose to restructure my dataset. I've been given an Excel file that contains dates, blood pressures and notes (fictitious data). The data read the long way (across) but I need to get the file to read down. The same date appears three times to because each blood pressure is recorded as systolic, diastolic and notes.&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="644"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="92"&gt;&lt;FONT size="2"&gt;Name&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="92"&gt;&lt;FONT size="2"&gt;22-Apr&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="92"&gt;&lt;FONT size="2"&gt;22-Apr&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="92"&gt;&lt;FONT size="2"&gt;22-Apr&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="92"&gt;&lt;FONT size="2"&gt;22-May&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="92"&gt;&lt;FONT size="2"&gt;22-May&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="92"&gt;&lt;FONT size="2"&gt;May-22&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;SBP&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;DBP&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;TI&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;SBP&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;DBP&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;TI&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;AAA&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;120&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;60&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;BBB&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;130&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;70&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;140&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;80&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;ACT&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;CCC&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;165&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;90&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;start ACE&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;DDD&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;115&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;70&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;EEE&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;135&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;75&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&lt;FONT size="2"&gt;BCT&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is how I'd like the dataset to look.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="276"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="92"&gt;Name&lt;/TD&gt;
&lt;TD width="92"&gt;Date&lt;/TD&gt;
&lt;TD width="92"&gt;SBP&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Name&lt;/TD&gt;
&lt;TD&gt;Date&lt;/TD&gt;
&lt;TD&gt;DBP&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Name&lt;/TD&gt;
&lt;TD&gt;Date&lt;/TD&gt;
&lt;TD&gt;TI&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Name&lt;/TD&gt;
&lt;TD&gt;Date&lt;/TD&gt;
&lt;TD&gt;SBP&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Name&lt;/TD&gt;
&lt;TD&gt;Date&lt;/TD&gt;
&lt;TD&gt;DBP&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Name&lt;/TD&gt;
&lt;TD&gt;Date&lt;/TD&gt;
&lt;TD&gt;TI&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm a bit stuck because of the data headers being in two rows. I've been looking at numerous examples but can't figure out how to do this. And help would be appreciated. Thank you.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2022 17:21:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-transpose-for-Excel-file-with-two-rows-for-headers/m-p/843191#M333368</guid>
      <dc:creator>joesmama</dc:creator>
      <dc:date>2022-11-08T17:21:40Z</dc:date>
    </item>
    <item>
      <title>Re: Proc transpose for Excel file with two rows for headers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-transpose-for-Excel-file-with-two-rows-for-headers/m-p/843197#M333370</link>
      <description>Take your first two rows into a separate data set. Transpose it to a long format. Create new variable names that have the date and measure, ie SBP_2022_04 &lt;BR /&gt;Rename the variables in the file. Then transpose it.&lt;BR /&gt;&lt;BR /&gt;If you can trust that it's always SBP, DBP, TI in that order you can simplify this a bit but I'm not a trusting person when it comes to badly formatted data.</description>
      <pubDate>Tue, 08 Nov 2022 17:43:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-transpose-for-Excel-file-with-two-rows-for-headers/m-p/843197#M333370</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-11-08T17:43:47Z</dc:date>
    </item>
    <item>
      <title>Re: Proc transpose for Excel file with two rows for headers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-transpose-for-Excel-file-with-two-rows-for-headers/m-p/843416#M333449</link>
      <description>&lt;P&gt;Thanks for you response. Assuming the SBP, DBP and TI are in the same order, how can I simplify this?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2022 16:48:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-transpose-for-Excel-file-with-two-rows-for-headers/m-p/843416#M333449</guid>
      <dc:creator>joesmama</dc:creator>
      <dc:date>2022-11-09T16:48:31Z</dc:date>
    </item>
    <item>
      <title>Re: Proc transpose for Excel file with two rows for headers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-transpose-for-Excel-file-with-two-rows-for-headers/m-p/843421#M333451</link>
      <description>Declare an array with the list of variables and loop through the columns to transpose the data.&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;array _dates(*) startVar--endVar; /*start of dates and end of dates*/&lt;BR /&gt;length measure $15.;&lt;BR /&gt;do i=1 to dim(_dates) by 3;&lt;BR /&gt;date = vname(_dates(i));&lt;BR /&gt;measure = "Systolic";&lt;BR /&gt;value = _dates(i); output;&lt;BR /&gt;measure = "Diastolic";&lt;BR /&gt;value = _dates(i+1); output;&lt;BR /&gt;measure = "Notes"; values=_dates(I+2); output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;I would probably actually recommend this structure myself so you're storing numeric and character data in different columns and can do calculations within a measurement.&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;array _dates(*) startVar -- endVar;&lt;BR /&gt;do i=1 to dim(_dates) by 3;&lt;BR /&gt;Date = vname(_dates(I));&lt;BR /&gt; Systolic = _dates(i);&lt;BR /&gt;Diastolic = _dates(i+1);&lt;BR /&gt;Notes = _dates(i+2);&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Wed, 09 Nov 2022 17:07:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-transpose-for-Excel-file-with-two-rows-for-headers/m-p/843421#M333451</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-11-09T17:07:24Z</dc:date>
    </item>
    <item>
      <title>Re: Proc transpose for Excel file with two rows for headers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-transpose-for-Excel-file-with-two-rows-for-headers/m-p/843443#M333460</link>
      <description>&lt;P&gt;An actual XLSX file?&amp;nbsp; Or a text file like a CSV file?&amp;nbsp; If the later it is much easier as you can then just read it in the way you want to start with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With an XLSX file read the file twice.&lt;/P&gt;
&lt;P&gt;Once to get the first row with the dates.&amp;nbsp; If you know how many columns (or can at least put an upper bound on how many you will accept) you can use the RANGE option to limit it to reading just the first row.&amp;nbsp; For example to get the first 26 columns use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import file="&amp;amp;fname" dbms=xlsx out=dates_wide replace;
  range='$A1:Z1' ;
  getnames=NO;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To read the first 702 columns use $A1:ZZ1. To get the first 18,278 columns use $A1:ZZZ1.&lt;/P&gt;
&lt;P&gt;The second time to get the actual data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import file="&amp;amp;fname" dbms=xlsx out=wide replace;
  range='$A2:' ;
  getnames=YES;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now transpose both of them:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=dates_wide out=dates(keep=col1 rename=(col1=date));
  var _all_;
run;
proc transpose data=wide out=tall(rename=(col1=value)) ;
   by A ;
   var _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can merge them together copying the DATE value from the first row onto every observation in the TALL dataset by using the POINT= option of the SET statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set tall;
  by A ;
  point+1;
  if first.A then point=1;
  set dates point=point;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Nov 2022 18:51:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-transpose-for-Excel-file-with-two-rows-for-headers/m-p/843443#M333460</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-09T18:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: Proc transpose for Excel file with two rows for headers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-transpose-for-Excel-file-with-two-rows-for-headers/m-p/843606#M333510</link>
      <description>&lt;P&gt;Thanks Reeza. I used your second suggestion and it worked nicely. Appreciate the help.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2022 15:38:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-transpose-for-Excel-file-with-two-rows-for-headers/m-p/843606#M333510</guid>
      <dc:creator>joesmama</dc:creator>
      <dc:date>2022-11-10T15:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: Proc transpose for Excel file with two rows for headers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-transpose-for-Excel-file-with-two-rows-for-headers/m-p/843607#M333511</link>
      <description>&lt;P&gt;Thank you Tom. I'm going to give this one a try as well.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2022 15:41:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-transpose-for-Excel-file-with-two-rows-for-headers/m-p/843607#M333511</guid>
      <dc:creator>joesmama</dc:creator>
      <dc:date>2022-11-10T15:41:47Z</dc:date>
    </item>
  </channel>
</rss>

