<?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: Converting report into CSV in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-report-into-CSV/m-p/534413#M146641</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/98762"&gt;@gskn&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below code should give you the idea how to read such data structures.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/**
the record layout:
  record_id 1-5
  emp_id    6-10
  emp_name  11-24
  job_id    25-33
  dept_id   34-37
**/

data 
  emp_data(keep=record_id rec_no emp_id emp_name job_id dept_id)
  emp_load_msg(keep=record_id rec_no message)
  ;
  infile datalines truncover;
  attrib record_id length=$5 rec_no length=$8;
  retain record_id;
  input @;
  if not missing(substrn(_infile_,1,1)) then 
    do;
      input 
        record_id $ 1-5
        emp_id    $ 6-10
        emp_name  $ 11-24
        job_id    $ 25-33
        dept_id   $ 34-37
        ;
      rec_no=scan(trim(_infile_),-1,'#');
      output emp_data;
    end;
    else
    if anydigit(substrn(_infile_,5,1)) then
      do;
        input
          @5 message $200.
          ;
        rec_no=scan(trim(_infile_),-1,'#');
        output emp_load_msg;
      end;

datalines;
REC0168319KAYING        MANAGER  1001                       ==&amp;gt; actual update record #1
    30227     INCORRECT DEPARTMENT ID                       ==&amp;gt; unique error number &amp;amp; error message.#1
REC0164567WALSH         HR       4001                       ==&amp;gt; actual update record #2     
    30227     INCORRECT EMPLOYEE ID                         ==&amp;gt; unique error number &amp;amp; error message.#2
REC0168319KAYING        MANAGER  1001                       ==&amp;gt; actual update record #3     
    30227     INCORRECT DEPARTMENT ID                       ==&amp;gt; unique error number &amp;amp; error message.#3
REC0168934JOHN          SALES    1001                       ==&amp;gt; actual update record #4     
    30227     INCORRECT DEPARTMENT ID                       ==&amp;gt; unique error number &amp;amp; error message.#4
    29040     INCORRECT EMPLOYEE ID                         ==&amp;gt; unique error number &amp;amp; error message.#4
REC0168345BLAZE         ANALYST  2001                       ==&amp;gt; actual update record #5     
REC0168212WADE          HR       4001                       ==&amp;gt; actual update record #6     
REC0168458JONAS         ANALYST  2001                       ==&amp;gt; actual update record #7     
    30227     INCORRECT DEPARTMENT ID                       ==&amp;gt; unique error number &amp;amp; error message.#5
    29040     INCORRECT EMPLOYEE ID                         ==&amp;gt; unique error number &amp;amp; error message.#5
    30227     INCORRECT DEPARTMENT ID                       ==&amp;gt; unique error number &amp;amp; error message.#6
    29040     INCORRECT EMPLOYEE ID                         ==&amp;gt; unique error number &amp;amp; error message.#6
    30227     INCORRECT DEPARTMENT ID                       ==&amp;gt; unique error number &amp;amp; error message.#6
;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 11 Feb 2019 10:07:55 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2019-02-11T10:07:55Z</dc:date>
    <item>
      <title>Converting report into CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-report-into-CSV/m-p/534378#M146631</link>
      <description>&lt;P&gt;Hi All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to convert a report into a csv file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the report in not consistent and i am having problem to break it down.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is sample report:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;REC0168319KAYING        MANAGER  1001
    30227     INCORRECT DEPARTMENT ID
REC0164567WALSH         HR       4001
    30227     INCORRECT EMPLOYEE ID
REC0168319KAYING        MANAGER  1001
    30227     INCORRECT DEPARTMENT ID
REC0168934JOHN          SALES    1001
    30227     INCORRECT DEPARTMENT ID
    29040     INCORRECT EMPLOYEE ID
REC0168345BLAZE         ANALYST  2001
REC0168212WADE          HR       4001
REC0168458JONAS         ANALYST  2001
    30227     INCORRECT DEPARTMENT ID
    29040     INCORRECT EMPLOYEE ID
    30227     INCORRECT DEPARTMENT ID
    29040     INCORRECT EMPLOYEE ID
    30227     INCORRECT DEPARTMENT ID&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;the record layout:

record_id&amp;nbsp;    1-5
emp_id&amp;nbsp; &amp;nbsp; &amp;nbsp;   6-10
emp_name 11-24
job_id          25-33
dept_id        34-37

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the report has record followed by error/reject comment.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are few instance with more than 1 error/reject comment. and some with multiple record followed by multiple error comment.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output layout:&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;record_id~emp_id~emp_name~job_id~dept_id~error_msg1~error_msg2&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;I am not able to handle when there are multiple records followed by multiple error messages.&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;can anyone help&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2019 06:14:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-report-into-CSV/m-p/534378#M146631</guid>
      <dc:creator>gskn</dc:creator>
      <dc:date>2019-02-11T06:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: Converting report into CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-report-into-CSV/m-p/534379#M146632</link>
      <description>I don't understand what you have and what you want as output. Please post data in usable form: a data-step creating the dataset that you want to export. Then add what you exactly expect as output. &lt;BR /&gt;</description>
      <pubDate>Mon, 11 Feb 2019 06:19:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-report-into-CSV/m-p/534379#M146632</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-02-11T06:19:43Z</dc:date>
    </item>
    <item>
      <title>Re: Converting report into CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-report-into-CSV/m-p/534387#M146636</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I don't understand what you have and what you want as output. Please post data in usable form: a data-step creating the dataset that you want to export. Then add what you exactly expect as output.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;we send record to update the database. The records that were not updated were returned to us as a report.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The sample report below. It has the update record (which was rejected)followed by error message.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;REC0168319KAYING        MANAGER  1001                       &lt;EM&gt;==&amp;gt; actual update record #1&lt;/EM&gt;
    30227     INCORRECT DEPARTMENT ID                       &lt;EM&gt;==&amp;gt; unique error number &amp;amp; error message.#1&lt;/EM&gt;
REC0164567WALSH         HR       4001                       &lt;EM&gt;==&amp;gt; actual update record #2&lt;/EM&gt;     
    30227     INCORRECT EMPLOYEE ID                         &lt;EM&gt;==&amp;gt; unique error number &amp;amp; error message.&lt;/EM&gt;#2
REC0168319KAYING        MANAGER  1001                       &lt;EM&gt;==&amp;gt; actual update record #3&lt;/EM&gt;     
    30227     INCORRECT DEPARTMENT ID                       &lt;EM&gt;==&amp;gt; unique error number &amp;amp; error message.&lt;/EM&gt;#3
REC0168934JOHN          SALES    1001                       &lt;EM&gt;==&amp;gt; actual update record #4&lt;/EM&gt;     
    30227     INCORRECT DEPARTMENT ID                       &lt;EM&gt;==&amp;gt; unique error number &amp;amp; error message.&lt;/EM&gt;#4
    29040     INCORRECT EMPLOYEE ID                         &lt;EM&gt;==&amp;gt; unique error number &amp;amp; error message.&lt;/EM&gt;#4
REC0168345BLAZE         ANALYST  2001                       &lt;EM&gt;==&amp;gt; actual update record #5&lt;/EM&gt;     
REC0168212WADE          HR       4001                       &lt;EM&gt;==&amp;gt; actual update record #6&lt;/EM&gt;     
REC0168458JONAS         ANALYST  2001                       &lt;EM&gt;==&amp;gt; actual update record #7&lt;/EM&gt;     
    30227     INCORRECT DEPARTMENT ID                       &lt;EM&gt;==&amp;gt; unique error number &amp;amp; error message.&lt;/EM&gt;#5
    29040     INCORRECT EMPLOYEE ID                         &lt;EM&gt;==&amp;gt; unique error number &amp;amp; error message.&lt;/EM&gt;#5
    30227     INCORRECT DEPARTMENT ID                       &lt;EM&gt;==&amp;gt; unique error number &amp;amp; error message.&lt;/EM&gt;#6
    29040     INCORRECT EMPLOYEE ID                         &lt;EM&gt;==&amp;gt; unique error number &amp;amp; error message.&lt;/EM&gt;#6
    30227     INCORRECT DEPARTMENT ID                       &lt;EM&gt;==&amp;gt; unique error number &amp;amp; error message.&lt;/EM&gt;#7&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am trying to breakdown this report into a delimited file. The report is not consistent pattern.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2019 06:58:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-report-into-CSV/m-p/534387#M146636</guid>
      <dc:creator>gskn</dc:creator>
      <dc:date>2019-02-11T06:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: Converting report into CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-report-into-CSV/m-p/534394#M146637</link>
      <description>Again: please post test-data in usable form. Is that report a text-file?</description>
      <pubDate>Mon, 11 Feb 2019 07:32:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-report-into-CSV/m-p/534394#M146637</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-02-11T07:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: Converting report into CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-report-into-CSV/m-p/534413#M146641</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/98762"&gt;@gskn&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below code should give you the idea how to read such data structures.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/**
the record layout:
  record_id 1-5
  emp_id    6-10
  emp_name  11-24
  job_id    25-33
  dept_id   34-37
**/

data 
  emp_data(keep=record_id rec_no emp_id emp_name job_id dept_id)
  emp_load_msg(keep=record_id rec_no message)
  ;
  infile datalines truncover;
  attrib record_id length=$5 rec_no length=$8;
  retain record_id;
  input @;
  if not missing(substrn(_infile_,1,1)) then 
    do;
      input 
        record_id $ 1-5
        emp_id    $ 6-10
        emp_name  $ 11-24
        job_id    $ 25-33
        dept_id   $ 34-37
        ;
      rec_no=scan(trim(_infile_),-1,'#');
      output emp_data;
    end;
    else
    if anydigit(substrn(_infile_,5,1)) then
      do;
        input
          @5 message $200.
          ;
        rec_no=scan(trim(_infile_),-1,'#');
        output emp_load_msg;
      end;

datalines;
REC0168319KAYING        MANAGER  1001                       ==&amp;gt; actual update record #1
    30227     INCORRECT DEPARTMENT ID                       ==&amp;gt; unique error number &amp;amp; error message.#1
REC0164567WALSH         HR       4001                       ==&amp;gt; actual update record #2     
    30227     INCORRECT EMPLOYEE ID                         ==&amp;gt; unique error number &amp;amp; error message.#2
REC0168319KAYING        MANAGER  1001                       ==&amp;gt; actual update record #3     
    30227     INCORRECT DEPARTMENT ID                       ==&amp;gt; unique error number &amp;amp; error message.#3
REC0168934JOHN          SALES    1001                       ==&amp;gt; actual update record #4     
    30227     INCORRECT DEPARTMENT ID                       ==&amp;gt; unique error number &amp;amp; error message.#4
    29040     INCORRECT EMPLOYEE ID                         ==&amp;gt; unique error number &amp;amp; error message.#4
REC0168345BLAZE         ANALYST  2001                       ==&amp;gt; actual update record #5     
REC0168212WADE          HR       4001                       ==&amp;gt; actual update record #6     
REC0168458JONAS         ANALYST  2001                       ==&amp;gt; actual update record #7     
    30227     INCORRECT DEPARTMENT ID                       ==&amp;gt; unique error number &amp;amp; error message.#5
    29040     INCORRECT EMPLOYEE ID                         ==&amp;gt; unique error number &amp;amp; error message.#5
    30227     INCORRECT DEPARTMENT ID                       ==&amp;gt; unique error number &amp;amp; error message.#6
    29040     INCORRECT EMPLOYEE ID                         ==&amp;gt; unique error number &amp;amp; error message.#6
    30227     INCORRECT DEPARTMENT ID                       ==&amp;gt; unique error number &amp;amp; error message.#6
;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Feb 2019 10:07:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-report-into-CSV/m-p/534413#M146641</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-02-11T10:07:55Z</dc:date>
    </item>
    <item>
      <title>Re: Converting report into CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-report-into-CSV/m-p/534452#M146656</link>
      <description>&lt;P&gt;thank you for reply. The report does not have record number at the end.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I included it to explain the report structure.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is actual report without record# at the end.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;REC0168319KAYING        MANAGER  1001      
    30227     INCORRECT DEPARTMENT ID      
REC0164567WALSH         HR       4001      
    30227     INCORRECT EMPLOYEE ID        
REC0168319KAYING        MANAGER  1001      
    30227     INCORRECT DEPARTMENT ID
REC0168934JOHN          SALES    1001      
    30227     INCORRECT DEPARTMENT ID
    29040     INCORRECT EMPLOYEE ID
REC0168345BLAZE         ANALYST  2001      
REC0168212WADE          HR       4001      
REC0168458JONAS         ANALYST  2001      
    30227     INCORRECT DEPARTMENT ID
    29040     INCORRECT EMPLOYEE ID
    30227     INCORRECT DEPARTMENT ID
    29040     INCORRECT EMPLOYEE ID
    30227     INCORRECT DEPARTMENT ID&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 11 Feb 2019 13:34:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-report-into-CSV/m-p/534452#M146656</guid>
      <dc:creator>gskn</dc:creator>
      <dc:date>2019-02-11T13:34:36Z</dc:date>
    </item>
    <item>
      <title>Re: Converting report into CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-report-into-CSV/m-p/534478#M146662</link>
      <description>&lt;P&gt;The report is in text file and it is input. I need to convert a report into a usable form (a delimited file).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Input report:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;REC0168319KAYING        MANAGER  1001      
    30227     INCORRECT DEPARTMENT ID      
REC0164567WALSH         HR       4001      
    29040     INCORRECT EMPLOYEE ID        
REC0168319KAYING        MANAGER  1001      
    30227     INCORRECT DEPARTMENT ID
REC0168934JOHN          SALES    1001      
    30227     INCORRECT DEPARTMENT ID
    29040     INCORRECT EMPLOYEE ID
REC0168345BLAZE         ANALYST  2001      
REC0168212WADE          HR       4001      
REC0168458JONAS         ANALYST  2001      
    30227     INCORRECT DEPARTMENT ID
    29040     INCORRECT EMPLOYEE ID
    30227     INCORRECT DEPARTMENT ID
    29040     INCORRECT EMPLOYEE ID
    30227     INCORRECT DEPARTMENT ID&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;REC_ID~EMP_ID~EMP_NAME~EMP_ROLE~DEPT_ID~Error01~Error02~
REC01~68319~KAYING ~MANAGER ~1001~30227 INCORRECT DEPARTMENT ID~
REC01~64567~WALSH ~HR ~4001~29040 INCORRECT EMPLOYEE ID~ 
REC01~68319~KAYING        ~MANAGER  ~1001~30227     INCORRECT DEPARTMENT ID~
REC01~68934~JOHN          ~SALES    ~1001~30227     INCORRECT DEPARTMENT ID~29040     INCORRECT EMPLOYEE ID~
REC01~68345~BLAZE         ~ANALYST  ~2001~30227     INCORRECT DEPARTMENT ID~29040     INCORRECT EMPLOYEE ID~
REC01~68212~WADE          ~HR       ~4001~30227     INCORRECT DEPARTMENT ID~29040     INCORRECT EMPLOYEE ID~
REC01~68458~JONAS         ~ANALYST  ~2001~30227     INCORRECT DEPARTMENT ID~&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2019 14:50:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-report-into-CSV/m-p/534478#M146662</guid>
      <dc:creator>gskn</dc:creator>
      <dc:date>2019-02-11T14:50:01Z</dc:date>
    </item>
    <item>
      <title>Re: Converting report into CSV</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-report-into-CSV/m-p/534603#M146713</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/98762"&gt;@gskn&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The values for record_id you give us are always the same. Not sure if that's just because it's not representative sample data or not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you need is something that ties the error messages to the data records. If the error messages always below to the latest data record then ideally just use record_id (if unique per data record) or create your own id - which could simply be a counter increased by 1 whenever you read a data record.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Else: I believe the code I've already posted should give you sufficient guidance to work out the last details yourself.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Feb 2019 20:16:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-report-into-CSV/m-p/534603#M146713</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-02-11T20:16:50Z</dc:date>
    </item>
  </channel>
</rss>

