Export to Excel/CSV

Reply
Regular Contributor
Posts: 150

Export to Excel/CSV

I have a SAS dataset I need to export to excel or as a csv file and it is not exporting correctly. When I export it changes some character variables to numeric. I have number saved as character because excel drops leading zeros and has been putting random decimal places in the beginning of the numbers. Any suggestions to fix this would be appreciated.

Respected Advisor
Posts: 4,920

Re: Export to Excel/CSV

Posted in reply to rfarmenta

You can force Excel to consider a field as text by prefixing it with an apostrophe. The apostrophe will not be displayed in the Excel worksheet.

libname xl Excel "path\myFile.xlsx";

proc sql;

create table xl.mySheet as

select

     myNumVar,

     cats("'", myCharNumVar) as myCharNumVar

from myData;

quit;

PG

PG
Ask a Question
Discussion stats
  • 1 reply
  • 258 views
  • 0 likes
  • 2 in conversation