Does anyone know by any chance how to export a txt file with double quotes and when the text field is blank it be
exported as ""?
For example:
field1 | field2 | field3 |
abc | 123 | XXX |
def | 456 | |
ghi | 654 | YYY |
I would like to export a txt file like this:
field1;field2;field3
"abc";123;"XXX"
"def";456;""
"ghi";654;"YYY"
use a $quote format? http://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm#n1m51h0mem3l...
Jaap's suggestion certainly works. Here is an alternative, You will need 'FILENAME' statement to address your destination instead of 'LOG':
data have;
infile cards truncover;
input (field1 field2 field3) (:$8.);
file log dsd dlm=';';
put field1 ~ field2 field3 ~;
cards;
abc 123 XXX
def 456 .
ghi 654 YYY
;
Regards,
Haikuo
In your code, whether ~ is used to create file with double quotes? If so, what symbol to use for producing a file with single quotes?
I don't know of a symbol for single quotes. You could do the single quoting with the quote function but you much also make sure the character variables have adequate to hold the two or more characters that will be added to the value. This would be easier if there were an $SQUOTE function similar to $QUOTE then you would not have the length problem. I suppose $SQUOTE could be written using PROC FMCP, we can leave that for another time.
data have; input field1 $ field2 field3 $; cards; abc 123 XXX def 456 . ghi 654 YYY ; run; ods listing close; ods csv file='c:\temp\y.txt' options(doc='help' Delimiter=';'); proc print data=have label noobs;run; ods csv close; ods listing;
Another way :
%ds2csv (data=have, runmode=b, csvfile=c:\temp\retail.csv);
Xia Keshan
Sure.
Then try HaiKuo's code.
filename x 'c:\temp\xx.csv'; data _null_; set have; file x dsd dlm=';'; if _n_=1 then put 'field1' 'field2' 'field3'; put field1 ~ field2 field3 ~; run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.