Date: Wed, 26 Mar 2008 14:22:03 -0400
Reply-To: "Audimar P. Bangi" <audi@SAS2THEMAX.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Audimar P. Bangi" <audi@SAS2THEMAX.COM>
Organization: sas2themax.com
Subject: Re: Exporting char field to CSV in single quotes
In-Reply-To: <C8AFBABB9BA3324690008DF6D28E76D129E25E@CSTUCPEXMB03.ad.charming.com>
Content-Type: text/plain; format=flowed; charset="iso-8859-1";
reply-type=original
Hi,
You can use my Notebook Professional program to accomplish what you want
without writing a single line of code. I can let you try it by registering
at http://sas2themax.com. E-mail me your userid so that I can give you
access to the Downloads section.
Regards, Audi
----- Original Message -----
From: "Ramsey, Julia" <Julia.Ramsey@CXTOWN.COM>
To: <SAS-L@LISTSERV.UGA.EDU>
Sent: Wednesday, March 26, 2008 11:35 AM
Subject: Exporting char field to CSV in single quotes
> Hi fellow SAS geeks,
>
> I've got some tables that need to be converted to CSV and sent to our IT
> department on a daily basis. Two of the fields appear numeric, but
> contain leading zeroes and/or spaces and thus need to be treated as
> character variables. With a regular PROC EXPORT, these fields are
> treated as numeric, which is not correct. IT wants these character
> variables surrounded in quotes, ie "09842."
> As per a few old SAS-L posts, I've tried applying the $quote. format to
> the outgoing table, but that doesn't seem to work-- the raw CSV contains
> three sets of quotes around the character variables, when I only need
> one.
> I feel like I'm missing something simple. Any ideas??
>
> Thanks in advance!
>
>
> SAMPLE DATA:
>
> data test;
> input item1 $ div1 item2 $ div2;
> cards;
> 00542 22 01685 15
> 00542 22 16895 42
> 00542 22 78420 20
> ;
> run;
>
> proc export data=test
> outfile='\\stuff\things.csv'
> dbms=csv
> replace;
> run;
>
>
> The resulting CSV file:
> 542,22,1685,15
> 542,22,16895,42
> 542,22,78420,20
>
>
> What IT wants to see:
> "00542",22,"01685",15
> "00542",22,"16895",42
> "00542,"22,"78420",20
>
>
> I've tried applying the quote format in the step immediately before the
> format, like this:
> proc sql;
> create table coolthings as select
> t1.item1 format $quote.,
> t2.div1
> from lib1.stuff t1, lib2.morestuff t2
> where t1.item1 = t2.item1
> order by t1.item1;
> quit;
>
>
> While I see the strings surrounded by (single) quotes when I open the
> CSV file in Excel, opening the file in Notepad gives me:
> """00542""",22,"""01685""",15
> """00542""",22,"""16895""",42
> """00542""",22,"""78420""",20
>
>
>
> .*^*.*^*.*^*.*^*.*^*.
> Julia Ramsey
> Crosstown Traders, Inc.
> (520) 745-4500, x4149
> Julia.Ramsey@cxtown.com
>
|