Kavitha
Kavitha

Reputation: 371

Export sas table to CSV

I have created a table in sas and Want to export to a CSV but I am facing a problem that when I export to csv the AGE value of 10-20 becomes OCT-20. I want to see as it is like sas table. How can I do it.

    ID   Age    Value
    1   0-10    3154
    2   35-45   0
    3   10-20   9527
    4   10-20   3856
    5   20-35   8111
    6   0-10    105
    7   10-20   5500
    8   10-20   5500
    9   0-10    1918
    10  0-10    2819


PROC EXPORT DATA=FORECAST
   OUTFILE='\\pwc-storage\BP&D\IMP_OUT\FORECAST.CSV'
   DBMS=csv REPLACE;
RUN;

CSV out put

ID  Age Value
1   0-10    3154
2   0-10    0
3   Oct-20  9527
4   Oct-20  3856
5   20-35   8111
6   0-10    105
7   Oct-20  5500
8   Oct-20  5500
9   0-10    1918
10  0-10    2819

Upvotes: 0

Views: 2889

Answers (1)

vasja
vasja

Reputation: 4792

This is caused by Excel trying to treat some values in AGE field as Date.

You should run Import Wizard in Excel to import the csv and mark field AGE as TEXT instead of default General option.

Alternatively, you could e.g. create a view on top of FORECAST table to add a single quote prefix to AGE values, so that you force Excel to treat it as text:

data FORECAT_EXPORT_VIEW / view=FORECAT_EXPORT_VIEW;
    length AGE $10;
    set FORECAST;
    AGE = catt("'", AGE);
run;

You'll run PROC EXPORT on top of view.

Upvotes: 4

Related Questions