BookmarkSubscribeRSS Feed
HarfordKaren
Calcite | Level 5

I am relatively new to SAS programming.  The state has modified how they want their data files.  They used to want .dat files and now have changed to .csv files with 2 header records (second one has the column headings). What is the best way to do this in a SAS program? 

1 REPLY 1
jwsquillace
SAS Employee

Here is SAS code that demonstrates how to use a DATA step to generate a CSV file with two lines for heading

data _NULL_;

  set sashelp.class;  /* replace with your data set name */

file 'c:\temp\test.csv' dlm=',';

if _N_ = 1 then do;

  put 'first line heading';  /* replace with your heading */

  put 'name,age,sex,height,weight'; /* replace with your variables */

end;

put name age sex height weight; /* replace with your variables */

run;

If you have more then 256 characters per output line, you need an LRECL parameter on the FILE statement.

I invite you to send email to support.sas.com if you have further questions.

Jan

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
  • 1 reply
  • 371 views
  • 3 likes
  • 2 in conversation