<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to split a sas dataset columnwise in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-sas-dataset-columnwise/m-p/409494#M279551</link>
    <description>&lt;P&gt;Not really, it rarely makes sense to split data out. To do something like this you would need to generate either the code as a whole or the keep lists, e.g.&lt;/P&gt;
&lt;PRE&gt;data _null_; 
  length klist $2000; 
  set sashelp.vcolumn (where=(libname="WORK" and memname="HAVE")); 
  retain klist; 
  retain i 1; 
  if mod(varnum,2)=0 then do; 
    klist=catx(" ",klist,name); 
    call execute('data want'||strip(put(i,best.))||"; set have (keep="||strip(klist)||"); run;"); 
    i=i+1; 
  end; 
  else do; 
    klist=catx(" ","pk_consumer_id bk_consumer_id pk_country_id fk_consumer_id",name);
  end; 
run;&lt;/PRE&gt;
&lt;P&gt;Change work to your library and memname to your dataset.&lt;/P&gt;</description>
    <pubDate>Wed, 01 Nov 2017 15:10:50 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-11-01T15:10:50Z</dc:date>
    <item>
      <title>How to split a sas dataset columnwise</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-sas-dataset-columnwise/m-p/409480#M279549</link>
      <description>&lt;P&gt;I have following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data tmp;
pk_consumer_id = 10;
bk_consumer_id = '10';
pk_country_id = 'uk';
fk_consumer_id = 10;
var_1 = 'a';
var_2 = 'b';
var_3 = 'c';
var_4 = 'd';
var_5 = 'e';
run;

data _null_;
set tmp;
array nums(*) _numeric_;
array chars(*) _character_;
n_col = dim(nums)+dim(chars);
call symput('n_col',n_col);
run;&lt;/PRE&gt;&lt;P&gt;My aim now is to split original file (tmp) into subsets with 2 columns with out knowing the names of variables within tmp (i.e. would like to reference the cols numerically). Is there any easy way how to proceed? Something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set tmp (keep=1:2);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your suggestions!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2017 14:33:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-sas-dataset-columnwise/m-p/409480#M279549</guid>
      <dc:creator>Uknown_user</dc:creator>
      <dc:date>2017-11-01T14:33:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a sas dataset columnwise</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-sas-dataset-columnwise/m-p/409489#M279550</link>
      <description>&lt;P&gt;use varnum in dictionary columns something like shown below. this is untested code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select name :col separated by ' '
 from dictionary.columns
 where memname = upcase("yourdatset")
and libname =upcase("yourlibname")
and varnum between 1 and 2;/*variables you want want 
 quit;


data want;
set have( drop = &amp;amp;col);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2017 14:56:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-sas-dataset-columnwise/m-p/409489#M279550</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2017-11-01T14:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a sas dataset columnwise</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-sas-dataset-columnwise/m-p/409494#M279551</link>
      <description>&lt;P&gt;Not really, it rarely makes sense to split data out. To do something like this you would need to generate either the code as a whole or the keep lists, e.g.&lt;/P&gt;
&lt;PRE&gt;data _null_; 
  length klist $2000; 
  set sashelp.vcolumn (where=(libname="WORK" and memname="HAVE")); 
  retain klist; 
  retain i 1; 
  if mod(varnum,2)=0 then do; 
    klist=catx(" ",klist,name); 
    call execute('data want'||strip(put(i,best.))||"; set have (keep="||strip(klist)||"); run;"); 
    i=i+1; 
  end; 
  else do; 
    klist=catx(" ","pk_consumer_id bk_consumer_id pk_country_id fk_consumer_id",name);
  end; 
run;&lt;/PRE&gt;
&lt;P&gt;Change work to your library and memname to your dataset.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2017 15:10:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-sas-dataset-columnwise/m-p/409494#M279551</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-11-01T15:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a sas dataset columnwise</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-sas-dataset-columnwise/m-p/409514#M279552</link>
      <description>&lt;P&gt;You could rename all columns to var1 - varX, but this will lead to&amp;nbsp;hardly readable&amp;nbsp;code. Why do you want to split, at all?&lt;/P&gt;</description>
      <pubDate>Wed, 01 Nov 2017 15:35:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-sas-dataset-columnwise/m-p/409514#M279552</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2017-11-01T15:35:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to split a sas dataset columnwise</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-sas-dataset-columnwise/m-p/409664#M279553</link>
      <description>&lt;P&gt;This might be a good application for CALL VNEXT, which allows you to retrieve the name, type, and length progressing from the first to last variable in the PDV.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename tmp1 temp;

data _null_;
  if 0 then set sashelp.class;
  length varname $32;
  file tmp;
  do I=1 to 2;
    call vnext(varname);
    put varname @;
  end;
run;

data want;
  set sashelp.class;
  keep %include tmp /source2;  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Nov 2017 22:15:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-a-sas-dataset-columnwise/m-p/409664#M279553</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-11-01T22:15:13Z</dc:date>
    </item>
  </channel>
</rss>

