<?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: deleting columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/deleting-columns/m-p/310566#M67008</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let no_of_col=7;
/* Sample dataset cars considered for code */
data cars;
set sashelp.cars;
run;

/* column list extracted */
proc contents data=cars out=column_nm varnum;
run;

proc sort data=column_nm out=col_nm_sorted(keep = libname memname name);
by varnum;
run;

data filtered_col;
set col_nm_sorted(obs=&amp;amp;no_of_col);
run;



proc sql noprint;
select name into :_col_name separated by ' '
from filtered_col;
quit;
%put &amp;amp;_col_name ;

data want;
set cars (keep = &amp;amp;_col_name);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have taken work.cars as an input dataset and kept first 7 columns&lt;/P&gt;</description>
    <pubDate>Thu, 10 Nov 2016 03:57:40 GMT</pubDate>
    <dc:creator>RahulG</dc:creator>
    <dc:date>2016-11-10T03:57:40Z</dc:date>
    <item>
      <title>deleting columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-columns/m-p/310558#M67004</link>
      <description>&lt;P&gt;I have data which include around 20-25 columns. I want to keep only first 7 columns and delete the remaining. How can i do that?&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2016 03:18:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-columns/m-p/310558#M67004</guid>
      <dc:creator>Jahanzaib</dc:creator>
      <dc:date>2016-11-10T03:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: deleting columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-columns/m-p/310564#M67007</link>
      <description>Please get the details of the variables in the dataset by &lt;BR /&gt;&lt;BR /&gt;proc contents data=x out=vars;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;After this sort the data by order of the variables with VARNUM&lt;BR /&gt;&lt;BR /&gt;proc sort data=vars;&lt;BR /&gt;by varnum;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;create a macro variable keep from proc sql&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;select name into:keep from vars where varnum&amp;lt;=7;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;%put &amp;amp;keep;&lt;BR /&gt;&lt;BR /&gt;Use this keep macro variable to keep only the required variables. &lt;BR /&gt;</description>
      <pubDate>Thu, 10 Nov 2016 03:48:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-columns/m-p/310564#M67007</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2016-11-10T03:48:17Z</dc:date>
    </item>
    <item>
      <title>Re: deleting columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-columns/m-p/310566#M67008</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let no_of_col=7;
/* Sample dataset cars considered for code */
data cars;
set sashelp.cars;
run;

/* column list extracted */
proc contents data=cars out=column_nm varnum;
run;

proc sort data=column_nm out=col_nm_sorted(keep = libname memname name);
by varnum;
run;

data filtered_col;
set col_nm_sorted(obs=&amp;amp;no_of_col);
run;



proc sql noprint;
select name into :_col_name separated by ' '
from filtered_col;
quit;
%put &amp;amp;_col_name ;

data want;
set cars (keep = &amp;amp;_col_name);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have taken work.cars as an input dataset and kept first 7 columns&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2016 03:57:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-columns/m-p/310566#M67008</guid>
      <dc:creator>RahulG</dc:creator>
      <dc:date>2016-11-10T03:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: deleting columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-columns/m-p/310603#M67014</link>
      <description>&lt;P&gt;The simplest way is to use list operator in SAS:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have (keep=&amp;lt;first&amp;gt;--&amp;lt;last&amp;gt;);
run;&lt;/PRE&gt;
&lt;P&gt;Replace &amp;lt;first&amp;gt; with the variable to start from and &amp;lt;last&amp;gt; with the last one - you of course know what these are as it is your data. &amp;nbsp;I would not rely on order of columns in the dataset - that can change very easliy and then you get different results.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Nov 2016 09:21:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-columns/m-p/310603#M67014</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-11-10T09:21:51Z</dc:date>
    </item>
  </channel>
</rss>

