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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 669 views
  • 0 likes
  • 3 in conversation