labradorchik
asked on
How to write records from one SAS dataset to multiple ASCII files or SAS datasets?
Hi everyone,
in SAS I am trying to sort one SAS dataset by a certain variable (var1) and then write all records to SAS datasets (name includes "var1") and ASCII files (name includes "var1"). I am thinking to do everything in two steps as below but I am not sure if Step 2 should be done in PROC SQL or maybe in a DATA step with macros? If anyone knows how to do Step 2 please let me know. Any suggestions or examples would be greatly appriciated.
Step 1. Sort olddata.sas7bdat SAS dataset by var1
Step 2. Write all records from olddata.sas7bdat for each unique var1 to its correcponding data<var1>.sas7bdat SAS datasets and data<var1>.in ASCII files
in SAS I am trying to sort one SAS dataset by a certain variable (var1) and then write all records to SAS datasets (name includes "var1") and ASCII files (name includes "var1"). I am thinking to do everything in two steps as below but I am not sure if Step 2 should be done in PROC SQL or maybe in a DATA step with macros? If anyone knows how to do Step 2 please let me know. Any suggestions or examples would be greatly appriciated.
Step 1. Sort olddata.sas7bdat SAS dataset by var1
Step 2. Write all records from olddata.sas7bdat for each unique var1 to its correcponding data<var1>.sas7bdat SAS datasets and data<var1>.in ASCII files
*********************
* Step 1- sorting initial dataset
***********************
proc sort data=olddata;
by var1;
run;
****************************
* Step 2 - creating data<var1>.sas7bdat
****************************
proc sql noprint;
select distinct var1 into : x separated by ' ' from olddata;
quit;
%macro create;
%do i = 1 %to %eval(%sysfunc(count(&x, %str( )))+1);
data data%scan(&x,&i.);
set olddata;
if var1 = "%scan(&x,&i.)";
run;
%end;
%mend;
%create
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
ASKER