The SAS Output Delivery System and reporting techniques

Using PUT to output simple csv with variables

Reply
N/A
Posts: 0

Using PUT to output simple csv with variables

data outdata.ivrs (keep = protocol site screen dob lbdt hgb tsat ferr gfr_cb gfr);
set outdata.indata;
file 'c:\Local\kimj\Studies\Luitpold\test.csv' dlm=',';
put protocol site screen dob lbdt hgb tsat ferr gfr_cb gfr;
run;

------------------------------------
Hello,

I'm creating a simple csv file using FILE and PUT in the above code.
I'm trying to insert the variable names in the first row automatically - what would be the easiest way to do so?

Thank you for your help.

James
Contributor
Posts: 29

Re: Using PUT to output simple csv with variables

Posted in reply to deleted_user
Try putting these lines in between your file and put lines

if _n_ = 1 then do;
put 'protocol' 'site' etc.;
end;
N/A
Posts: 0

Re: Using PUT to output simple csv with variables

Thank you!!!

That was a neat trick - I was looking for all over the documentations for some special options!

James
SAS Super FREQ
Posts: 8,864

Re: Using PUT to output simple csv with variables

Posted in reply to deleted_user
Also, since this is the ODS forum ;-) ODS CSV will do it automatically without any PUT statements at all and it will work with other procedures, not just PROC PRINT and if you want titles or bylines, then you can use ODS CSVALL instead.
cynthia
[pre]
ODS CSV file='c:\temp\wombat.csv';
proc print data=sashelp.class;
run;
ODS CSV CLOSE;
[/pre]
Ask a Question
Discussion stats
  • 3 replies
  • 167 views
  • 0 likes
  • 3 in conversation