Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9227217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:01:03+00:00 2026-06-18T05:01:03+00:00

When I am exporting a SAS dataset to csv; it is trimming all the

  • 0

When I am exporting a SAS dataset to csv; it is trimming all the leading spaces in the characters.
Please help me to retain all the leading spaces in the csv output. The statement used is:

Proc Export Data = Globl_Mth_Sumry
OutFile = "&GMUPath.\20&RptYr._&RptMt.\03 Output\01 GMU\&Brnd_Abbr.\&Brnd._&Mkt._Globl_Mth_Sumry_&RptMt.&RptYr.&NeuronQTR..csv" 
DBMS = CSV Replace; 
Run;

So, there is a column containing the list of countries which is like

Asia
India
China
etc.
But the csv file is showing it like:-
Asia
India
China.

Please help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:01:05+00:00Added an answer on June 18, 2026 at 5:01 am

    I find this an interesting question, largely because I was confident I knew the answer… to find out I didn’t.

    This is technically a solution, and if you’re in a time crunch perhaps is sufficient, though I suspect it’s too unwieldy to use in a practical fashion. First I generate the data (input using $CHAR8. to preserve leading spaces), then I output it using fixed column output rather than list output.

    data test;
    input
    @1 x $CHAR8.
    @9 y $CHAR8.;
    format x y $char8.;
    datalines;
         USA   China
      Canada N Korea
      Russia  Mexico
    ;;;;
    run;
    
     data _null_;
     file "c:\temp\test.csv" lrecl=80 dropover;
     set test;
     if _n_ = 1 then do;
     put "x,y";
     end;
     put @1 x $char8. @9 "," @10 y $char8.;
     run;
    

    Unfortunately, using DBMS=CSV does not seem to allow $CHAR8. to function as you would expect. I don’t know why that is. The solution I expected was to write it out like this:

    data _null_;
    file 'c:\temp\test.csv' delimiter=',' DROPOVER lrecl=32767;
      if _n_ = 1 then        /* write column names or labels */
       do;
         put
            "x"
         ','
            "y"
         ;
       end;
     set  TEST;
     put x $ :char8. y $ :char8.;
      run;
    

    which is essentially the code printed to the log by PROC EXPORT, then with :$CHAR8. after each variable. For whatever reason, that (and a bunch of other similar things) didn’t work. ODS CSV also does not seem to work for preserving leading spaces.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Any ideas on Exporting HTML5 Form data to CSV please? I can only use
Exporting select query data from mysql to csv & opening with excel, the leading
Exporting some data from mysql to a csv file using FasterCSV. I'd like the
Here i am exporting the datatables in a dataset to excel.How to make the
i am exporting data to csv, while exporting i want to split by every
Am exporting data to csv. after 25000 records , memory exhausted. Memory limit increasing
I am working on exporting a data.frame to a csv for use in an
I'm exporting a CSV to firefox using the following code: string csv = dataTable.ToCSV();
I am exporting a csv file in to mysql db using load data infile
I am exporting a Excel (.xls) sheet to dataset. In that excel i am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.