My report has a requirement to have specific report header it the first row (Cell1) and then save th eoutput as csv shoing column labels since column names don't match the required naming convention. I am using SAS Enterprise Guide 8.3 and managed to export the variable lables rahter than names. However, I still can't get to include the header in the first cell. Here are suggested codes:
---------------------------------------------------------
The codes didn't generate any eorros but didn't add the text in the first row either. I appreciate any suggestions?
desired csv output:
First Row: Consent
Second Row: Data Column Labels (rahter names)
Third row on: Data
Thank you,
Delimited files with no headers are TRIVIAL to create with SAS data step (see the last step below). And it takes only a little extra effort to generate a header row first. You could add your extra headers line at that point.
First get the names and labels (if any) of the variables into a dataset. PROC TRANSPOSE with zero input observations is a simple way to do that.
proc transpose data=FINAL(obs=0) out=names;
var _all_;
run;
Now use that dataset of names to write your first two lines. You can use COALESCEC() to have it use the NAME when the variable does not have a LABEL attached.
data _null_;
file "C:\output.csv" dsd;
length _name_ $32 _label_ $256 ;
set names;
if _n_=1 then put 'Consent';
_label_=coalescec(_label_,_name_);
put _label_ @ ;
run;
Then just run a second data step to append the actual data lines by adding the MOD option to the FILE statement.
data _null_;
file "C:\output.csv" dsd mod;
set FINAL;
put (_all_) (+0);
run;
Thank you Tom. It worked like a charm.
Helal
You gotta need CSVALL destination,
but if you have a big table, this way would be very slowly.
data FINAL;
set sashelp.class;
label sex='sex sfder';
run;
ods _all_ close;
ods csvall file='c:\temp\a\output.csv';
title;
ods text='Consent';
proc report data=final nowd ;
define _all_/display;
run;
ods csvall close;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.