<?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: Export to .csv value comes in a separate line in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Export-to-csv-value-comes-in-a-separate-line/m-p/348859#M80835</link>
    <description>Hi ballardw, You are right the excel I imported the file from had a carriage return on it's value and that is causing the problem. However if I export it back to excel it seem OK, but .csv or .txt doesn't seem OK. Thanks,</description>
    <pubDate>Mon, 10 Apr 2017 20:00:17 GMT</pubDate>
    <dc:creator>mlogan</dc:creator>
    <dc:date>2017-04-10T20:00:17Z</dc:date>
    <item>
      <title>Export to .csv value comes in a separate line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-to-csv-value-comes-in-a-separate-line/m-p/348823#M80820</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I have the following SAS data table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; State &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Comment &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Action ID &amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;123 &amp;nbsp; &amp;nbsp;NY &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Good &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;458425&amp;nbsp;&lt;/P&gt;
&lt;P&gt;234 &amp;nbsp; &amp;nbsp;TX &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Moderate but &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;256532&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; Liveable&lt;/P&gt;
&lt;P&gt;543 &amp;nbsp; &amp;nbsp;CA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Not bad &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;526547 &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC EXPORT DATA=Have
OUTFILE="C:\Want.csv"
DBMS=csv
REPLACE;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;When I use the above code to export the table in .csv, I get and extra rows where the secord line of the comment field is thrown off to an extra row. Can someone please tell me how to fix it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; State &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Comment &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Action ID &amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;123 &amp;nbsp; &amp;nbsp;NY &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Good &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;458425&amp;nbsp;&lt;/P&gt;
&lt;P&gt;234 &amp;nbsp; &amp;nbsp;TX &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Moderate but &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Liveable &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;256532&lt;/P&gt;
&lt;P&gt;543 &amp;nbsp; &amp;nbsp;CA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Not bad &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;526547 &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2017 18:18:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-to-csv-value-comes-in-a-separate-line/m-p/348823#M80820</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2017-04-10T18:18:15Z</dc:date>
    </item>
    <item>
      <title>Re: Export to .csv value comes in a separate line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-to-csv-value-comes-in-a-separate-line/m-p/348824#M80821</link>
      <description>&lt;P&gt;Check the file in a text editor not Excel.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2017 18:20:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-to-csv-value-comes-in-a-separate-line/m-p/348824#M80821</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-10T18:20:29Z</dc:date>
    </item>
    <item>
      <title>Re: Export to .csv value comes in a separate line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-to-csv-value-comes-in-a-separate-line/m-p/348830#M80825</link>
      <description>&lt;P&gt;Hi Reeza, Same result when I export this file to .txt format OR open the file with text editor.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2017 18:45:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-to-csv-value-comes-in-a-separate-line/m-p/348830#M80825</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2017-04-10T18:45:20Z</dc:date>
    </item>
    <item>
      <title>Re: Export to .csv value comes in a separate line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-to-csv-value-comes-in-a-separate-line/m-p/348835#M80828</link>
      <description>&lt;P&gt;Can you attaachyour sas dataset here (you may have to zip it first .. I'm not sure)? That would definitely help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2017 19:00:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-to-csv-value-comes-in-a-separate-line/m-p/348835#M80828</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-04-10T19:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: Export to .csv value comes in a separate line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-to-csv-value-comes-in-a-separate-line/m-p/348853#M80832</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35631"&gt;@mlogan&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi Reeza, Same result when I export this file to .txt format OR open the file with text editor.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you see this behavior and have not opened and saved in Excel it may mean that your comment text has a line feed, carriage return, both or other special characters&amp;nbsp;embedded in the text.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2017 19:52:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-to-csv-value-comes-in-a-separate-line/m-p/348853#M80832</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-04-10T19:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: Export to .csv value comes in a separate line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-to-csv-value-comes-in-a-separate-line/m-p/348859#M80835</link>
      <description>Hi ballardw, You are right the excel I imported the file from had a carriage return on it's value and that is causing the problem. However if I export it back to excel it seem OK, but .csv or .txt doesn't seem OK. Thanks,</description>
      <pubDate>Mon, 10 Apr 2017 20:00:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-to-csv-value-comes-in-a-separate-line/m-p/348859#M80835</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2017-04-10T20:00:17Z</dc:date>
    </item>
    <item>
      <title>Re: Export to .csv value comes in a separate line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-to-csv-value-comes-in-a-separate-line/m-p/348865#M80840</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Export to .csv value comes in a separate line

see
https://goo.gl/ZIZI9A
https://communities.sas.com/t5/Base-SAS-Programming/Export-to-csv-value-comes-in-a-separate-line/m-p/348823

I assume excel was the source not your SAS dataset?
It is always best to work with data in its original format.

You can translate the passthru query below to native SAS and use
your SAS daatset as input it should fix your 'alt-enters'.

You can solve this without the excel source but I thought I would
show users how to fix the issue on the excel side.
The SAS dataset probably came from excel?

You probably gave carriage-returns&amp;lt;alt-enter&amp;gt;, '0D'x,  in your
data. It is best to fix this on the excel side.

I am going to assume you have the excel file;

HAVE
====

  +--------------------------------------------------------------+
  |     A    ] |    B       |     C      |    D                  |
  +--------------------------------------------------------------+
1 |   ID       |  STATE     |  ACTION    |   COMMENT             |
  +------------+------------+------------+-----------------------+
2 |  123       |   NY        |  458425   |   Good                |
  +------------+------------+------------+-----------------------+
3 |  234       |   TX       |   2565325  |   Moderate&amp;lt;alt-enter&amp;gt; |
  |            |            |            |   But&amp;lt;alt-enter&amp;gt;      |
  |            |            |            |   Liveable            |
  +------------+------------+------------+-----------------------+
4 |  543       |   CA       |   526547   |   Not&amp;lt;alt-enter&amp;gt;      |
  |            |            |            |   Bad                 |
  +------------+------------+------------+-----------------------+

As a side note here is what a the csv looks like with the alt enters.

COMMENT,ID,STATE,ACTIONG
ood,123,NY,458425
Moderate
but
Liveable",234,TX,256532
Not
bad",543,CA,526547

WANT SAS dataset with spaces for alt_enter
===========================================

Up to 40 obs WORK.WANT total obs=3

Obs     ID    STATE    ACTION    COMMENT_FIX

 1     123     NY      458425    Good
 2     234     TX      256532    Moderate but Liveable
 3     543     CA      526547    Not bad

WORKING CODE
============

   Passthru to excel (replace alt-enter with space

      Replace(comment,chr(13),chr(32))  as comment_fix


*                _                              _               _
 _ __ ___   __ _| | _____       _ __  _ __ ___ | |__      __  _| |_____  __
| '_ ` _ \ / _` | |/ / _ \_____| '_ \| '__/ _ \| '_ \ ____\ \/ / / __\ \/ /
| | | | | | (_| |   &amp;lt;  __/_____| |_) | | | (_) | |_) |_____&amp;gt;  &amp;lt;| \__ \&amp;gt;  &amp;lt;
|_| |_| |_|\__,_|_|\_\___|     | .__/|_|  \___/|_.__/     /_/\_\_|___/_/\_\
                               |_|
;


%utlfkil(d:/xls/have.xlsx);
libname xel "d:/xls/have.xlsx";

data xel.have;
informat comment $32.;
input id State$ Comment$ Action$ ;
comment=tranwrd(comment,'z','0D'x);
cards4;
123 NY Good 458425
234 TX ModeratezbutzLiveable 256532
543 CA Notzbad 526547
;;;;
run;quit;

libname xel clear;

*                    _   _                       __ _
 _ __   __ _ ___ ___| |_| |__  _ __ _   _       / _(_)_  __
| '_ \ / _` / __/ __| __| '_ \| '__| | | |_____| |_| \ \/ /
| |_) | (_| \__ \__ \ |_| | | | |  | |_| |_____|  _| |&amp;gt;  &amp;lt;
| .__/ \__,_|___/___/\__|_| |_|_|   \__,_|     |_| |_/_/\_\
|_|
;

proc sql dquote=ansi;
  connect to excel (Path="d:\xls\have.xlsx" mixed=yes);
    create
        table want as
    select * from connection to Excel
        ( Select
            id
           ,state
           ,action
           ,Replace(comment,chr(13),chr(32))  as comment_fix
         from
           [have$]
        ) ;
    disconnect from Excel;
Quit;


2441  proc sql dquote=ansi;
2442    connect to excel (Path="d:\xls\have.xlsx" mixed=yes);
NOTE: Data source is connected in READ ONLY mode.

2443      create
2444          table want as
2445      select * from connection to Excel
2446          ( Select
2447              id
2448             ,state
2449             ,action
2450             ,Replace(comment,chr(13),chr(32))  as comment_fix
2451           from
2452             [have$]
2453          ) ;
NOTE: Table WORK."WANT" created, with 3 rows and 4 columns.

2454      disconnect from Excel;
2455  Quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.02 seconds
      cpu time            0.01 seconds




&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Apr 2017 20:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-to-csv-value-comes-in-a-separate-line/m-p/348865#M80840</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-04-10T20:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: Export to .csv value comes in a separate line</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Export-to-csv-value-comes-in-a-separate-line/m-p/348899#M80857</link>
      <description>&lt;P&gt;Excel is just "hiding" the character. If you need to use the file in another program that expects actual CSV then you'll need to find out which character(s) and remove it from the string before export.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Apr 2017 21:08:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Export-to-csv-value-comes-in-a-separate-line/m-p/348899#M80857</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-04-10T21:08:59Z</dc:date>
    </item>
  </channel>
</rss>

