0

Dataset has 4 variables:

id v1 v2 v3

I want to automate the creation of 3 datasets, each with 2 variables: id and one of the 3 variables from the original dataset. I know I want to use an array, but not sure exactly how to set up the macro code.

Need to extend this to dataset with large number of variables.

Joe
  • 62,789
  • 6
  • 49
  • 67
Lisle
  • 1,620
  • 2
  • 16
  • 22
  • Why do you need so many datasets? How about just making one dataset in a vertical format. – Tom Aug 26 '15 at 21:40
  • If you use array, all columns must be the same type. So transpose and split the data. – Reeza Aug 26 '15 at 22:26

1 Answers1

-1

4 variables to make 3 datasets, the simplest way will be just hardcode it?

data v1(keep=id v1) v2(keep=id v2) v3(keep=id v3);
set have;
run;

Sorry, missed that part, here is the update, and you are right, in my code 'Array' is used:

data _null_;
set have;
array var v1-v200; /*suppose they are all numeric*/
length codegen $ 10000;
do over var;
varname=vname(var);
codegen=catx(' ', codegen, catx(' ',varname,'(keep=id',varname,')'));
end;
call execute ('data '||codegen||'; set have;run;');
stop;
run;
Haikuo Bian
  • 906
  • 6
  • 7
  • I've simplified the problem, solution needs to be extended to a dataset with 200 columns. – Lisle Aug 26 '15 at 21:13