<?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: Importing a .xlsx file into SAS with header in 2 row and data in 4 row in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-xlsx-file-into-SAS-with-header-in-2-row-and-data-in/m-p/353389#M82492</link>
    <description>&lt;P&gt;In other words, exactly what I said, there is no easy way to do this.&lt;/P&gt;</description>
    <pubDate>Tue, 25 Apr 2017 18:51:18 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2017-04-25T18:51:18Z</dc:date>
    <item>
      <title>Importing a .xlsx file into SAS with header in 2 row and data in 4 row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-xlsx-file-into-SAS-with-header-in-2-row-and-data-in/m-p/353229#M82440</link>
      <description>&lt;P&gt;How can i import excel having .XLSX Extension &amp;nbsp;using proc import where header start in 2 row and data start in 4 row.I know keywords namerow and startrow used in xls but same is not working in xlsx.i dont want to use range option because i have diffrent excel and want to make code generic.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2017 15:27:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-a-xlsx-file-into-SAS-with-header-in-2-row-and-data-in/m-p/353229#M82440</guid>
      <dc:creator>tarunchitkara</dc:creator>
      <dc:date>2017-04-25T15:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: Importing a .xlsx file into SAS with header in 2 row and data in 4 row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-xlsx-file-into-SAS-with-header-in-2-row-and-data-in/m-p/353231#M82442</link>
      <description>&lt;P&gt;Gosh, I hate Excel. I understand why the documentation for R strongly discourages the use of Excel for data import.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyway, to solve your problem, in Excel, delete rows 1 and 3, and then use SAS PROC IMPORT.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2017 15:30:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-a-xlsx-file-into-SAS-with-header-in-2-row-and-data-in/m-p/353231#M82442</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-04-25T15:30:19Z</dc:date>
    </item>
    <item>
      <title>Re: Importing a .xlsx file into SAS with header in 2 row and data in 4 row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-xlsx-file-into-SAS-with-header-in-2-row-and-data-in/m-p/353235#M82443</link>
      <description>&lt;P&gt;Thank you but i dont want to delete anythng manually . I need a keyword that makes any row as header and data row.For ex--&amp;gt;for xls extension in proc import we use namerow=2 ,datarow=4 to make 2 row as header and 4 row from where data starts.&lt;/P&gt;&lt;P&gt;In my case there are many files and data is jumbled up.so i need keyword that i can use.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2017 15:34:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-a-xlsx-file-into-SAS-with-header-in-2-row-and-data-in/m-p/353235#M82443</guid>
      <dc:creator>tarunchitkara</dc:creator>
      <dc:date>2017-04-25T15:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: Importing a .xlsx file into SAS with header in 2 row and data in 4 row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-xlsx-file-into-SAS-with-header-in-2-row-and-data-in/m-p/353238#M82444</link>
      <description>&lt;P&gt;Sorry to inform you that I am not aware of a simple solution that will do what you ask.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps the good news is that some expert here has a solution and I will learn the solution&amp;nbsp;as well as you.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2017 15:38:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-a-xlsx-file-into-SAS-with-header-in-2-row-and-data-in/m-p/353238#M82444</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-04-25T15:38:14Z</dc:date>
    </item>
    <item>
      <title>Re: Importing a .xlsx file into SAS with header in 2 row and data in 4 row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-xlsx-file-into-SAS-with-header-in-2-row-and-data-in/m-p/353384#M82490</link>
      <description>&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/variable-names-in-quot-row-2-quot-how-to-let-PROC-IMPORT-to/td-p/68009" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/variable-names-in-quot-row-2-quot-how-to-let-PROC-IMPORT-to/td-p/68009&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"&lt;SPAN&gt;- you can use import procedure with GETNAMES=NO, DATAROW=3, GUESSINGROWS= (default 20 - you may increase it depending on your file size) and after importing it use a data step or proc datasets to change the variables name."&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So, to sum:&lt;/SPAN&gt;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;SPAN&gt;Create two sas macro variables,&amp;nbsp;&amp;amp;namerow = 2 and &amp;amp;datarow=4&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;Import the data WITHOUT GETNAMES, so that the variable names will consistently be temp names&lt;/LI&gt;&lt;LI&gt;Create an ID on your table using monotonic() or an incrementing data step&lt;/LI&gt;&lt;LI&gt;Write a macro, or an elegant SAS INTO: statement, to rename the variables based on &amp;amp;namerow&lt;/LI&gt;&lt;LI&gt;Write a data step that overwrites the current dataset, where the ID is less than &amp;amp;datarow&lt;/LI&gt;&lt;LI&gt;Profit&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Tue, 25 Apr 2017 18:45:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-a-xlsx-file-into-SAS-with-header-in-2-row-and-data-in/m-p/353384#M82490</guid>
      <dc:creator>thomp7050</dc:creator>
      <dc:date>2017-04-25T18:45:29Z</dc:date>
    </item>
    <item>
      <title>Re: Importing a .xlsx file into SAS with header in 2 row and data in 4 row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-xlsx-file-into-SAS-with-header-in-2-row-and-data-in/m-p/353389#M82492</link>
      <description>&lt;P&gt;In other words, exactly what I said, there is no easy way to do this.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2017 18:51:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-a-xlsx-file-into-SAS-with-header-in-2-row-and-data-in/m-p/353389#M82492</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-04-25T18:51:18Z</dc:date>
    </item>
    <item>
      <title>Re: Importing a .xlsx file into SAS with header in 2 row and data in 4 row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-xlsx-file-into-SAS-with-header-in-2-row-and-data-in/m-p/353395#M82494</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Perhaps you are right, Paige. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tarun, if you find that this is not an easy solution and you would like some assistance&amp;nbsp;I would be happy to&amp;nbsp;assist! &amp;nbsp;I have conducted similar work before and it would be a pleasure for me to help you out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Patrick&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2017 19:03:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-a-xlsx-file-into-SAS-with-header-in-2-row-and-data-in/m-p/353395#M82494</guid>
      <dc:creator>thomp7050</dc:creator>
      <dc:date>2017-04-25T19:03:46Z</dc:date>
    </item>
    <item>
      <title>Re: Importing a .xlsx file into SAS with header in 2 row and data in 4 row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-xlsx-file-into-SAS-with-header-in-2-row-and-data-in/m-p/353559#M82541</link>
      <description>thank you thomp,yes i need some easy way like we do in xls so that i need to just change number for header row and start row</description>
      <pubDate>Wed, 26 Apr 2017 05:11:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-a-xlsx-file-into-SAS-with-header-in-2-row-and-data-in/m-p/353559#M82541</guid>
      <dc:creator>tarunchitkara</dc:creator>
      <dc:date>2017-04-26T05:11:53Z</dc:date>
    </item>
    <item>
      <title>Re: Importing a .xlsx file into SAS with header in 2 row and data in 4 row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-xlsx-file-into-SAS-with-header-in-2-row-and-data-in/m-p/353685#M82575</link>
      <description>&lt;P&gt;For your perusal. &amp;nbsp;I am sure there may be some efficiencies you could add but I only took about 20 min coding time with it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Patrick&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*IMPORT YOUR DATA, WITH GETNAMES = NO AND MIXED=YES*/
PROC IMPORT OUT= WORK.HAVE 
            DATAFILE= "C:\Users\USERNAME\Documents\have.xls" 
            DBMS=EXCEL REPLACE;
     RANGE="Sheet1$";  
     GETNAMES=NO;
     MIXED=YES;
     SCANTEXT=YES;
     USEDATE=YES;
     SCANTIME=YES;
RUN;

/*SET YOUR MACRO VARIABLES*/
%LET NAMEROW = 2;
%LET DATAROW = 4;

/*INSERT THE ROWID*/
PROC SQL;
CREATE TABLE HAVE_NEW AS
SELECT MONOTONIC() AS ID, * FROM HAVE;
QUIT;

/*GET ALL OF THE COLUMN NAMES IN THE HAVE SET*/
PROC SQL;
CREATE TABLE COLNAMES AS
SELECT NAME FROM DICTIONARY.COLUMNS WHERE MEMNAME = 'HAVE_NEW' AND NAME NOT IN ('ID');
QUIT;

/*SET THE LENGTH OF THE BLANK NEWNAME COLUMN*/
DATA COLNAMES;
SET COLNAMES;
LENGTH NEWNAME $ 80;
FORMAT NEWNAME $8.; 
RUN;

/*CREATE A MACRO THAT WE WILL USE TO UPDATE NEWNAME WITH THE SPECIFIED CRITERIA*/
%MACRO ROWNAMES(COLNAME);
PROC SQL;
UPDATE COLNAMES SET NEWNAME = (SELECT &amp;amp;COLNAME FROM HAVE_NEW WHERE ID = &amp;amp;NAMEROW) WHERE NAME = '%STR(&amp;amp;COLNAME)';
QUIT;
%MEND;

/*EXECUTE THE MACRO FOR EACH OF THE OLD NAMES*/
DATA COLNAMES;
SET COLNAMES;
CALL EXECUTE("%ROWNAMES("||TRIM(NAME)||")");
RUN;

/*CREATE A MACRO VARIABLE WITH A LIST OF EACH OF THE OLD AND NEW COLUMN NAMES
, WHICH WE WILL USE IN THE RENAME STATEMENT*/
PROC SQL;
SELECT TRIM(NAME)||"="||TRIM(NEWNAME) INTO :NEWVAR SEPARATED BY " " FROM COLNAMES;
QUIT;

/*CREATE A MACRO VARIABLE WITH A LIST OF EACH OF THE NEW COLUMN NAMES
, WHICH WE WILL USE IN THE LABEL STATEMENT*/
PROC SQL;
SELECT TRIM(NEWNAME)||"="||TRIM(NEWNAME) INTO :NEWLABEL SEPARATED BY " " FROM COLNAMES;
QUIT;
 
/*CHANGE THE NAMES, AND THE LABELS, AND ONLY SELECT DATA THAT ARE GE OUR DATAROW*/
DATA HAVE_NEW;
SET HAVE_NEW(RENAME=(&amp;amp;NEWVAR));
WHERE ID &amp;gt;= &amp;amp;DATAROW;
LABEL &amp;amp;NEWLABEL;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Apr 2017 13:32:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-a-xlsx-file-into-SAS-with-header-in-2-row-and-data-in/m-p/353685#M82575</guid>
      <dc:creator>thomp7050</dc:creator>
      <dc:date>2017-04-26T13:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: Importing a .xlsx file into SAS with header in 2 row and data in 4 row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Importing-a-xlsx-file-into-SAS-with-header-in-2-row-and-data-in/m-p/353717#M82578</link>
      <description>&lt;P&gt;How about .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc import datafile='/folders/myfolders/have.xlsx' out=have1 dbms=xlsx replace;
run;

proc import datafile='/folders/myfolders/have.xlsx' out=want dbms=xlsx replace;
datarow=4;
run;

proc transpose data=have1(obs=1) out=temp;
 var _all_;
run;

data _null_;
 set temp end=last;
 if _n_=1 then call execute('proc datasets library=work nolist nodetails;modify want;rename ');
 call execute(catx('=',_name_,col1));
 if last then call execute(';quit;');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Apr 2017 14:34:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Importing-a-xlsx-file-into-SAS-with-header-in-2-row-and-data-in/m-p/353717#M82578</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-04-26T14:34:47Z</dc:date>
    </item>
  </channel>
</rss>

