04-09-2015 01:32 PM
I am fairly new to SAS and have been trying to figure of how to export a dataset into multiple pipe delimited text files based on the field PPG ID.
Lets assume my input dataset named stars_report_in is like this
|PPG ID||Member ID||Member Name||Cycle End Date|
I want text files created with file naming convention like this: <PPG ID>_Report_<Cycle End Date>.txt.
So first text file generated will be named 1011_Report_04072015.txt and will have data in pipe delimited format like this
Second text file will be named 5674_Report_04072015.txt and will contain data in pipe delimited format like this below
and so on. Any help on this would be really appreciated. I use SAS EG 7.1 to write all my code.
09-11-2015 11:42 AM
You'll need to explicitly write your export in a data _null_ step but then you can use the FILEVAR option to split the files automatically.
Here's an example based on the SASHELP.CARS dataset. Note the DLM option used to specify the delimiter and that the header names are explicitly defined.
PROC SORT DATA=SASHELP.CARS OUT=CARS; BY make; RUN; DATA _NULL_; SET cars; *Dataset to be exported; BY make; *Variable that file is to be split on; *Create path to file that is to be exported; if first.make then out_file=cats('C:\_localdata\temp\', trim(make), ".txt"); file temp filevar=out_file dlm='|' dsd; *If first value of make then output column names; if first.make then put 'Make|Model|MPG_HIGHWAY|MPG_CITY'; *Output variables; put make model mpg_highway mpg_city; run;