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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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