<?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: Tricky excel data to be imported to sas dataset! in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Tricky-excel-data-to-be-imported-to-sas-dataset/m-p/923125#M363450</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile datalines4 dsd truncover firstobs=2;
  input @;
length Order Document $ 80;
retain  Order Document;
if _infile_ =: 'Order' then do;Order=scan(_infile_,2,',:');delete;end;
if _infile_ =: 'Document' then do;Document=scan(_infile_,2,',:');delete;end;
input (a1-a11) (:$100.);
  datalines4;
First Name,Last Name, NPN/A#,Order Date,Quantity,Item Product Name,Item Price,User Role,User State,User Home Market,CMS
Order #: O-AMS123,,,,,,,,,,
Document #: D-AMS342,,,,,,,,,,
Kain,Flory,34566732 ,12/28/2023,1,Sample sample,$0.00 ,BRKR,LA ,,Sample1
Order #: O-AMS797,,,,,,,,,,
Document #: D-AMS562,,,,,,,,,,
James,Brown,34589732 ,12/28/2023,1,Sample sample,$0.00 ,BRKR,LA ,,Sample2
Johny,David,34589452 ,12/28/2023,1,Sample sample,$0.00 ,BRKR,LA ,,Sample3
;;;;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 05 Apr 2024 09:17:37 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2024-04-05T09:17:37Z</dc:date>
    <item>
      <title>Tricky excel data to be imported to sas dataset!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tricky-excel-data-to-be-imported-to-sas-dataset/m-p/923089#M363434</link>
      <description>&lt;P&gt;I have an excel file where the data is as below&lt;/P&gt;&lt;P&gt;|Firstname | Lastname |&lt;BR /&gt;| -----&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;| --------&amp;nbsp; &amp;nbsp; &amp;nbsp; |&lt;BR /&gt;|Order#: AMS1 |&lt;BR /&gt;|Document# Doc1|&lt;BR /&gt;|John | Fury |&lt;BR /&gt;|James | Berry |&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I want to export this kind of excel file in SAS dataset and transform data as&lt;/P&gt;&lt;P&gt;|Order | Document |Firstname |Lastname |&lt;BR /&gt;| -----| -------- | -------- | -------- |&lt;BR /&gt;| AMS1 | Doc1 | John | Fury |&lt;BR /&gt;| AMS1 | Doc1 | James | Berry |&lt;/P&gt;&lt;P&gt;Either this can be transformed in excel itself and them imported into SAS dataset or&lt;BR /&gt;imported into SAS first and then transformed.&lt;BR /&gt;Please help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2024 03:30:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tricky-excel-data-to-be-imported-to-sas-dataset/m-p/923089#M363434</guid>
      <dc:creator>sumi_saslearner</dc:creator>
      <dc:date>2024-04-05T03:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: Tricky excel data to be imported to sas dataset!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tricky-excel-data-to-be-imported-to-sas-dataset/m-p/923090#M363435</link>
      <description>&lt;P&gt;Save your Excel as .csv and then share some representative sample data so we can fully understand the data structure. Don't use any placeholders but create a "real" data structure that contains all the cases that need to be covered (like header line, intermediate empty lines etc.). Below an example how this could look like.&lt;/P&gt;
&lt;PRE&gt;Order#: AMS1
Document# Doc1
John,Fury
James,Berry
Order#: AMS2
Document# Doc2
John,Doe
James,Brown&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2024 03:59:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tricky-excel-data-to-be-imported-to-sas-dataset/m-p/923090#M363435</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-04-05T03:59:27Z</dc:date>
    </item>
    <item>
      <title>Re: Tricky excel data to be imported to sas dataset!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tricky-excel-data-to-be-imported-to-sas-dataset/m-p/923101#M363438</link>
      <description>&lt;P&gt;data is as follows in CSV&lt;/P&gt;&lt;P&gt;First Name,Last Name, NPN/A#,Order Date,Quantity,Item Product Name,Item Price,User Role,User State,User Home Market,CMS&lt;BR /&gt;Order #: O-AMS123,,,,,,,,,,&lt;BR /&gt;Document #: D-AMS342,,,,,,,,,,&lt;BR /&gt;Kain,Flory,34566732 ,12/28/2023,1,Sample sample,$0.00 ,BRKR,LA ,,Sample1&lt;BR /&gt;Order #: O-AMS797,,,,,,,,,,&lt;BR /&gt;Document #: D-AMS562,,,,,,,,,,&lt;BR /&gt;James,Brown,34589732 ,12/28/2023,1,Sample sample,$0.00 ,BRKR,LA ,,Sample2&lt;BR /&gt;Johny,David,34589452 ,12/28/2023,1,Sample sample,$0.00 ,BRKR,LA ,,Sample3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2024 07:54:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tricky-excel-data-to-be-imported-to-sas-dataset/m-p/923101#M363438</guid>
      <dc:creator>sumi_saslearner</dc:creator>
      <dc:date>2024-04-05T07:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: Tricky excel data to be imported to sas dataset!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tricky-excel-data-to-be-imported-to-sas-dataset/m-p/923107#M363440</link>
      <description>&lt;P&gt;Expected Output is :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Order,Document,First Name,Last Name, NPN/A#,Order Date,Quantity,Item Product Name,Item Price,User Role,User State,User Home Market,CMS&lt;BR /&gt;O-AMS123,D-AMS342,Kain,Flory,34566732 ,12/28/2023,1,Sample sample,$0.00 ,BRKR,LA ,,Sample1&lt;BR /&gt;O-AMS797,D-AMS562,James,Brown,34589732 ,12/28/2023,1,Sample sample,$0.00 ,BRKR,LA ,,Sample2&lt;BR /&gt;O-AMS797,D-AMS562,Johny,David,34589452 ,12/28/2023,1,Sample sample,$0.00 ,BRKR,LA ,,Sample3&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2024 08:02:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tricky-excel-data-to-be-imported-to-sas-dataset/m-p/923107#M363440</guid>
      <dc:creator>sumi_saslearner</dc:creator>
      <dc:date>2024-04-05T08:02:56Z</dc:date>
    </item>
    <item>
      <title>Re: Tricky excel data to be imported to sas dataset!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tricky-excel-data-to-be-imported-to-sas-dataset/m-p/923116#M363445</link>
      <description>&lt;P&gt;Here you go&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path     =%sysfunc(pathname(work));
%let csv_file =test.csv;

/* create sample .csv */
data _null_;
  file "&amp;amp;path\&amp;amp;csv_file";
  infile datalines4;
  input;
  put _infile_;
  datalines4;
First Name,Last Name, NPN/A#,Order Date,Quantity,Item Product Name,Item Price,User Role,User State,User Home Market,CMS
Order #: O-AMS123,,,,,,,,,,
Document #: D-AMS342,,,,,,,,,,
Kain,Flory,34566732 ,12/28/2023,1,Sample sample,$0.00 ,BRKR,LA ,,Sample1
Order #: O-AMS797,,,,,,,,,,
Document #: D-AMS562,,,,,,,,,,
James,Brown,34589732 ,12/28/2023,1,Sample sample,$0.00 ,BRKR,LA ,,Sample2
Johny,David,34589452 ,12/28/2023,1,Sample sample,$0.00 ,BRKR,LA ,,Sample3
;;;;

/* read sample .csv into SAS table */
data want;
  attrib 
    order       length=$15 informat=$15.
    document    length=$15 informat=$15.
    first_name  length=$40 informat=$40.
    last_name   length=$40 informat=$40.
    /* ...and so on ... */
    ;
  retain order document;

  infile "&amp;amp;path\&amp;amp;csv_file" truncover dsd dlm=',' firstobs=2;
  input order_ind:$8. @;
  if order_ind='Order #:' then
    do;
      input @9 order;
      input @12 document;
    end;
  input @1
    first_name
    last_name
    /* ...and so on ... */
    ;
  drop order_ind;

run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1712307364013.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/95234i59BEF5708892C55D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1712307364013.png" alt="Patrick_0-1712307364013.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2024 08:56:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tricky-excel-data-to-be-imported-to-sas-dataset/m-p/923116#M363445</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-04-05T08:56:11Z</dc:date>
    </item>
    <item>
      <title>Re: Tricky excel data to be imported to sas dataset!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tricky-excel-data-to-be-imported-to-sas-dataset/m-p/923125#M363450</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  infile datalines4 dsd truncover firstobs=2;
  input @;
length Order Document $ 80;
retain  Order Document;
if _infile_ =: 'Order' then do;Order=scan(_infile_,2,',:');delete;end;
if _infile_ =: 'Document' then do;Document=scan(_infile_,2,',:');delete;end;
input (a1-a11) (:$100.);
  datalines4;
First Name,Last Name, NPN/A#,Order Date,Quantity,Item Product Name,Item Price,User Role,User State,User Home Market,CMS
Order #: O-AMS123,,,,,,,,,,
Document #: D-AMS342,,,,,,,,,,
Kain,Flory,34566732 ,12/28/2023,1,Sample sample,$0.00 ,BRKR,LA ,,Sample1
Order #: O-AMS797,,,,,,,,,,
Document #: D-AMS562,,,,,,,,,,
James,Brown,34589732 ,12/28/2023,1,Sample sample,$0.00 ,BRKR,LA ,,Sample2
Johny,David,34589452 ,12/28/2023,1,Sample sample,$0.00 ,BRKR,LA ,,Sample3
;;;;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Apr 2024 09:17:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tricky-excel-data-to-be-imported-to-sas-dataset/m-p/923125#M363450</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-04-05T09:17:37Z</dc:date>
    </item>
    <item>
      <title>Re: Tricky excel data to be imported to sas dataset!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tricky-excel-data-to-be-imported-to-sas-dataset/m-p/923129#M363453</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your Solution also works perfectly.&amp;nbsp; Awesome! Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2024 09:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tricky-excel-data-to-be-imported-to-sas-dataset/m-p/923129#M363453</guid>
      <dc:creator>sumi_saslearner</dc:creator>
      <dc:date>2024-04-05T09:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Tricky excel data to be imported to sas dataset!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Tricky-excel-data-to-be-imported-to-sas-dataset/m-p/923130#M363454</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot for this!&lt;/P&gt;</description>
      <pubDate>Fri, 05 Apr 2024 09:40:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Tricky-excel-data-to-be-imported-to-sas-dataset/m-p/923130#M363454</guid>
      <dc:creator>sumi_saslearner</dc:creator>
      <dc:date>2024-04-05T09:40:50Z</dc:date>
    </item>
  </channel>
</rss>

