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;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.