> There is in 9.2, a
> delimiter= option that allows you to change the
> delimiter from a comma to a tab character (which is
> 09'x, I believe) for ODS CSV.
That will be a nice feature. I look forward to using 9.2, soon perhaps.
The features of the FILE and PUT statement plus the call routine VNEXT make the data step solution fairly concise.
filename FT24F001 temp lrecl=512;
file FT24F001 dsd dlm='09'x;
if _n_ eq 1 then link nameRow;
length _LABEL_ $128 _NAME_ $32;
if _n_ eq 1 then do;
if _name_ eq '_LABEL_' then leave;
_label_ = vlabelx(_name_);
put _label_ @;
The SUGI paper that describes the OPTIONS suboption list and the DELIMITER suboption was written for SAS 9.1.3, so I believe you CAN get the delimiter, you just have to do some extra work because it's not included automatically with SAS (as it is in 9.2). http://support.sas.com/rnd/base/ods/odsmarkup/p236-31.pdf
Although this note talks about installing and using the ExcelXP tagset template, the information about installing a tagset template and using the ODS PATH statement, also apply for updates to the CSV tagset template: http://support.sas.com/kb/32/394.html
Sorry for reviving this thread, I got pointed to it from another thread.
data _null_, I like the simplicity of your data step, and the way you got around enumerating variables.
Fyi, I made a small macro out of it, for those (frequent) cases when tweaking the output is not needed.
%macro write_CSV(fileref= /* REQD: export fileref */
,dataset= /* REQD: dataset name, including options if necessary */
,delimiter=',' /* OPTN: eg: '09'x and ' ' for tab and space */
,firstrow=LABEL /* OPTN: Values: LABEL or NAME or NONE */
,addquotes=SPECIALCHAR /* OPTN: Values: ALLVAR or ALLCHAR or SPECIALCHAR */
file &fileref dlm=&delimiter %if %upcase(&addquotes) ne ALLCHAR %then dsd;;
%if %upcase(&addquotes)=ALLCHAR %then format _CHARACTER_ $quote.;;
%if %upcase(&firstrow) ne NONE %then if _N_ = 1 then link firstrow;;
put (_ALL_)(%if %upcase(&addquotes)=ALLVAR %then~;;
length __LABEL__ $256 __NAME__ $32;
do while( __NAME__ ne '__LABEL__' );
__LABEL__ = vlabelx(__NAME__);
if __NAME__ ne '__LABEL__' then put __%upcase(&firstrow)__ @;
One question though: how come all PDV variables are not output when put (_ALL_) is run?
Fixed, André, thank you.
I usually try to end my %if tests with a double ;; to remove %str() clutter, but I thought I'd post a more formal version... I have reverted to my old self now. That will teach me!
Do you know why some PDV variables are not output when put (_ALL_) is run? I am still perplexed.
I ran a much simpler test and found that the simple PUT _ALL_ writes out everything, including _N_ and _ERROR_, as shown below. If you're seeing something else, you might want to work with Tech Support or redo your macro to see if you can figure out where things might be going wrong.
format _CHARACTER_ $quote.;
if _N_ = 1 then link firstrow;
put 'What will be written out?';