A very common question on forums and help boards appears to be “How do I write a macro to do XYX?”. Often times a macro isn’t required. This is part one of an ongoing series into how to accomplish a task WITHOUT using a macro.
The first example answers the question of how to Split a data set into multiple files. Any file generated using a file statement can be generated using this method. I will be using the FILEVAR option of a file statement to split the SASHELP.CARS data set into multiple text files, one for each Make. The process and code is below, hope you find it helpful!
This is a two step process:
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(‘/folders/myfolders/’, trim(make));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;
This is a cross post from Statistics and other stuff from a geek
Code is also available here:
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.