BookmarkSubscribeRSS Feed
deleted_user
Not applicable
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
3 REPLIES 3
garybald
Calcite | Level 5
Try putting these lines in between your file and put lines

if _n_ = 1 then do;
put 'protocol' 'site' etc.;
end;
deleted_user
Not applicable
Thank you!!!

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

James
Cynthia_sas
Diamond | Level 26
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]

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1849 views
  • 0 likes
  • 3 in conversation