BookmarkSubscribeRSS Feed
lathabrewer
Calcite | Level 5

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 IDMember IDMember NameCycle End Date
1011123David Thorne04/07/2015
1011234Macy Davis
04/07/2015
5674567Deanna Summers
04/07/2015
5674789Tabitha Adams
04/07/2015

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!!!

1 REPLY 1
Reeza
Super User

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1320 views
  • 0 likes
  • 2 in conversation