Date: Fri, 13 Feb 2004 13:31:23 -0500
Reply-To: "Chakravarthy, Venky" <Venky.Chakravarthy@PFIZER.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Chakravarthy, Venky" <Venky.Chakravarthy@PFIZER.COM>
Subject: Re: output csv file with quoted character vars
Content-Type: text/plain; charset="iso-8859-1"
Hi Quentin.
Since the _file_ buffer can also be used as a variable like _infile_
starting with version 8.2, isn't it possible to manipulate this the same
way. Use a trailing @ and then manipulate _file_ then simply release the
manipulated buffer for output. The following code worked. However, I am sure
you can improve upon this to dynamically determine where the missing values
may occur:
data _null_;
set a;
file "c:\c_data\junk\txt\me.txt" dlm = "," ;
format _numeric_ miss. ;
format _character_ $quote3200.; *See Peter Crawford 5/27/2003 SAS-L post;
put name text misstext1 misstext2 num1 num2 num3 num4 num5 @ ;
_file_ = tranwrd ( _file_ , ", , ," , ",,," ) ;
put ;
run;
_________________________________
Venky Chakravarthy
E-mail: swovcc_AT_hotmail_DOT_com
-----Original Message-----
From: Quentin McMullen [mailto:quentin_mcmullen@BROWN.EDU]
Sent: Friday, February 13, 2004 11:14 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: output csv file with quoted character vars
Hi All,
I'm trying to create a csv file with character values in double quotes.
Thanks to SAS-L archives (esp Peter Crawford's posts about $quote.
format), I've gotten as far as:
*-------------------;
data a;
name="Quentin";
text='I can be text with " and , embedded in me';
misstext1=" ";
misstext2=" ";
num1=1;
num2=2;
num3=.;
num4=.;
num5=5;
run;
proc format;
value miss
.=' '
other=[best32.]
;
run;
data _null_;
set a;
file "c:\junk\me.txt" dlm = "," ;
format _numeric_ miss. ;
format _character_ $quote3200.; *See Peter Crawford 5/27/2003 SAS-L post;
put name text misstext1 misstext2 num1 num2 num3 num4 num5;
run;
*-------------------;
Tha above will put:
"Quentin","I can be text with "" and , embedded in me","","",1,2, , ,5
The problem is, when there are missing numerics, I dont want a blank
between the commas. So I want the output to be:
"Quentin","I can be text with "" and , embedded in me","","",1,2,,,5
Any easy way of doing this. I tried changing the format to .='', and SAS
got confused. Also tried missing='' but no joy there either. The DSD
option gets rid of the blanks, put adds an extra level of quotes.
I like the simplicity of the above put statement. If possible, I'd prefer
to avoid adding pointer controls, formats, etc. into the put statement.
But it wouldn't be the end of the world if that is the only way to
accomplish the goal....
Kind Regards,
--Quentin
LEGAL NOTICE
Unless expressly stated otherwise, this message is confidential and may be privileged. It is intended for the addressee(s) only. Access to this E-mail by anyone else is unauthorized. If you are not an addressee, any disclosure or copying of the contents of this E-mail or any action taken (or not taken) in reliance on it is unauthorized and may be unlawful. If you are not an addressee, please inform the sender immediately.
|