Hi guys,
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 | |
---|---|---|---|---|
1011 | 123 | David Thorne | 04/07/2015 | |
1011 | 234 | Macy Davis |
| |
5674 | 567 | Deanna Summers |
| |
5674 | 789 | Tabitha Adams |
|
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
1011|123|David Thorne|04/07/2015
1011|234|Macy Davis|04/07/2015
Second text file will be named 5674_Report_04072015.txt and will contain data in pipe delimited format like this below
5674|567|Deanna Summers|04/07/2015
5674|789|Tabitha Adams|04/07/2015
,pipe_delimited
and so on. Any help on this would be really appreciated. I use SAS EG 7.1 to write all my code.
Thanks!!!
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;
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: