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
SAS Super FREQ
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]

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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