The SAS Output Delivery System and reporting techniques

Export Multiple Datasets into one DLM/CSV file

Accepted Solution Solved
Reply
Contributor
Posts: 37
Accepted Solution

Export Multiple Datasets into one DLM/CSV file

[ Edited ]

Hey,

 

I am looking to export multiple data sets into one DLM/CSV file, column names are not the same and formats are different. So far I have:

 

PROC EXPORT DATA=TEMP1

OUTFILE='C:\myfile'

DBMS=DLM REPLACE;

PUTNAMES=NO;

DELIMITER='|';

RUN;

 

I still need data files TEMP2 and TEMP3 added. Any help would be appreciated.

 

Thanks.


Accepted Solutions
Solution
‎04-04-2016 04:02 PM
Super User
Posts: 9,856

Re: Export Multiple Datasets into one DLM/CSV file

Use MOD option .





data _null_;
 set sashelp.class;
 file '/folders/myfolders/x.txt' mod delimiter='|' dsd;
 put (_all_) (:);
run;

data _null_;
 set sashelp.cars;
 file '/folders/myfolders/x.txt' mod delimiter='|' dsd;
 put (_all_) (:);
run;


View solution in original post


All Replies
Super User
Posts: 19,023

Re: Export Multiple Datasets into one DLM/CSV file

You need to use a data step instead. 

 

It it also seems like a bad idea, I would hate to receive a file like that. 

Solution
‎04-04-2016 04:02 PM
Super User
Posts: 9,856

Re: Export Multiple Datasets into one DLM/CSV file

Use MOD option .





data _null_;
 set sashelp.class;
 file '/folders/myfolders/x.txt' mod delimiter='|' dsd;
 put (_all_) (:);
run;

data _null_;
 set sashelp.cars;
 file '/folders/myfolders/x.txt' mod delimiter='|' dsd;
 put (_all_) (:);
run;


Super User
Super User
Posts: 7,682

Re: Export Multiple Datasets into one DLM/CSV file

Hi,

 

Thats fundamentally against the purpose of a CSV file.  A CSV file is defined as a text file, with one row or fewer of column headers, with subsequent records detailing the data of those columns, delimited by a comma.  To that effeect if I was to recieve your described file I would reject it, and I would be surprised if anyone willingly accepts it as such.  Export each data strcuture to its own file - you would need to document this in any data transfer agreement document anyways.

 

There are other options out there if you need to ship data as flat file but with structure, JSON and XML can both be used to contain multiple different structures within one file.  The question you have to ask is wether its worth the effort, most of the time just create one CSV file per dataset is simplest.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 454 views
  • 2 likes
  • 4 in conversation