Last active
August 25, 2017 05:22
-
-
Save xiaodaigh/571439f1d218591f6d4a20e9b1fc33fb to your computer and use it in GitHub Desktop.
A SAS macro to split a dataset (.sas7bdat) into datasets where each resultant dataset contains exactly one column of the original data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data a; | |
do i = 1 to 10000; | |
b = i; | |
output; | |
end; | |
run; | |
%include "path/to/split_into_columns.sas"; | |
libname outlib "path/to/output/dataset/"; | |
%split_into_columns(a, outlib); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%macro split_into_columns(ds, outlib); | |
proc contents data = &ds. out = contents noprint; | |
run; | |
data _null_; | |
set contents nobs = nn; | |
if _n_ = 1 then do; | |
call execute("data "); | |
end; | |
call execute(cat("&outlib..",cats(name),"(keep=",cats(name),")")); | |
if _n_ = nn then do; | |
call execute(";set &ds.;"); | |
call execute("run;"); | |
end; | |
run; | |
%mend split_into_columns; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment