Skip to content

Instantly share code, notes, and snippets.

@xiaodaigh
Last active August 25, 2017 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xiaodaigh/571439f1d218591f6d4a20e9b1fc33fb to your computer and use it in GitHub Desktop.
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
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);
%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