08-31-2011 11:20 PM
Greetings ODS Tagset Gurus.
I am working on a customised CSV tagset that has the following changes:
This I have done successfully. The problem remains is that the CSV file created contains a blank line at both the top and the bottom.
I started with the custom tagset from here:
and tweaked it like this:
notes 'This is the MDR CSV template';
define event table;
*/define event put_value;
define event header;
put ',' /if ^cmp( COLSTART, '1');
start:put ',' /if ^cmp( COLSTART, '1'
put ''''; */end
stacked_columns = OFF;
I then tested the tagset like this:
ods Tagsets.csv_mdr file = "test.csv" ;
proc print data = sashelp.class noobs;
ods Tagsets.csv_mdr close;
I am running SAS 9.1.3 SP4 under Windows. I suspect a tweak of the row event is required because if you comment this out all data ends up on the same line. Would appreciate some help in what this tweak should be!
09-01-2011 10:03 AM
I would use a different approach. I would use PROC REPORT with the NOHEADER option to get rid of the column headers in the report file. Then I would just write a tagset template that inherited everything from regular CSV, but only got rid of the quotes. There is an EVENT for QUOTES. I would essentially turn it off, as shown in the code below. This bypasses the need to tinker with the ROW event. If you want to pursue your solution, then I suggest you try to track down the "extra" lines by finding the places where you write NL (newline) by selectively taking them out until you find the one(s) that are causing the issue.
define tagset Tagsets.myCsv;
notes "This is the changed CSV definition no quotes";
define event quotes;
ods tagsets.mycsv file='c:\temp\test2.csv';
proc report data=sashelp.shoes noheader nowd;
where region = 'Western Europe';
column region subsidiary product sales inventory;
ods tagsets.mycsv close;
09-06-2011 12:44 AM
Great solution Cynthia. However I want to scale this up to a dataset with 100,000 rows and 64 columns. Unfortunately PROC REPORT fails with out of memory errors on this volume of data with the CSV tagset. PROC PRINT works fine. I have managed to get it working with PROC PRINT using the official CSV tagset (change in bold) but only when the last column is fully populated, by using an event row like below. But I really want it to handle even totally missing columns. Thanks a lot for your help.
define event row;
do /if $cell_count;
eval $cell_count 0;
/*-- End of second row, only thing there is the --*/
/*-- rowheaders. print the data cell that were saved --*/
/*-- from the row above. --*/
else /if $$row;
put nl / if $VALUE ;
09-16-2011 01:03 AM
In the end I solved this without ODS. OK, its not as flexible, but at least it gets the job done, and is pretty quick!
%macro export_csv_noheader (dsname =
filename exTemp temp;
proc export data = &dsname
outfile = exTemp
dbms = csv
infile extemp firstobs = 2;
filename exTemp CLEAR;
09-22-2011 03:17 AM
There is no more another datastep. use putnames=no option.
proc export data = sashelp.class
outfile = 'c:\class.csv'
dbms = csv
09-22-2011 04:29 PM
Thanks Ksharp. Unfortunately I forgot to mention I am limited to SAS 9.1.3, and PUTNAMES only came in with 9.2. I live in hope that we may get upgraded some day....