LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (March 2008, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 26 Mar 2008 08:35:20 -0700
Reply-To:   "Ramsey, Julia" <Julia.Ramsey@CXTOWN.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Ramsey, Julia" <Julia.Ramsey@CXTOWN.COM>
Subject:   Exporting char field to CSV in single quotes
Content-Type:   text/plain; charset="us-ascii"

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


Back to: Top of message | Previous page | Main SAS-L page