0

I have a table cust_base with 1000 variables. And I have a text file contents1 containing the names of 250 variables separated by tab, that I actually need to work with. I want to do something similar to:

%include "/location/contents1.txt";
data new_cust_base(keep = &contents1.txt);
set cust_base;
run;

Is this the correct approach/syntax? Or is there a better way to go about it? I tried digging online, but couldn't find much. Thanks a lot.

IndigoChild
  • 842
  • 3
  • 11
  • 29

1 Answers1

2

You can %include source code as the interior of a keep statement.

set …;
KEEP
  %include "/location/contents1.txt";
;

Working example:

data _null_;
  file 'c:\temp\keeplist.tab';
  put 'name' "09"x 'age' "09"x 'weight';
run;

data work.class;
  set sashelp.class;

  KEEP
    %include 'c:\temp\keeplist.tab';
  ;
run;
Richard
  • 25,390
  • 3
  • 25
  • 38
  • Be aware that some SAS Versions don't like to include files with to long line. So if he has only one line he might be run better to change tab into newline before import or else variables at the end might be cut off. – Lee Aug 20 '19 at 06:19