<?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: subset dataset by variable name in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/subset-dataset-by-variable-name/m-p/266357#M52486</link>
    <description>&lt;P&gt;Sorry, do you want column names? &amp;nbsp;If so then query sashelp.vcolumns, or dictionary.columns:&lt;BR /&gt;data want; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; set sashelp.vcolumn (where=(libname="WORK" and memname="YOURDATASET"));&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the values in the coulmns then you can use a generic reference:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  gep=sum(of salary:);
run;&lt;/PRE&gt;
&lt;P&gt;However all that aside, its really not a good idea to name your variables with "data" - in this case a date. &amp;nbsp;You could end up with lots of variables, and your code will become difficult to work with as the strcuture changes, and even within a datarow may not be the same. &amp;nbsp;Far better to work with normalised data&amp;amp;colon;&lt;/P&gt;
&lt;P&gt;NAME &amp;nbsp; SURNAME &amp;nbsp;ADDRESS &amp;nbsp;SALARY_DATE &amp;nbsp;SALARY&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;Do remember the data you program on does not need to be the same as output data, you can always transpose at the end.&lt;/P&gt;</description>
    <pubDate>Tue, 26 Apr 2016 13:10:14 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-04-26T13:10:14Z</dc:date>
    <item>
      <title>subset dataset by variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subset-dataset-by-variable-name/m-p/266353#M52485</link>
      <description>&lt;P&gt;Dear experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;let's assume that I have a adata set containing the following variables:&lt;/P&gt;&lt;P&gt;name, surname, age, address, salary201401,&amp;nbsp;&lt;SPAN&gt;salary201402,&amp;nbsp;salary201403...&amp;nbsp;salary201512&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I qould like to use a proc sql or a data step to get the following variables:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- name&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;- all the salaries (i.e. variables contains "salary")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any suggestion?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks a lot&lt;/SPAN&gt;&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>Tue, 26 Apr 2016 13:43:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subset-dataset-by-variable-name/m-p/266353#M52485</guid>
      <dc:creator>Sir_Highbury</dc:creator>
      <dc:date>2016-04-26T13:43:57Z</dc:date>
    </item>
    <item>
      <title>Re: subset dataset by variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subset-dataset-by-variable-name/m-p/266357#M52486</link>
      <description>&lt;P&gt;Sorry, do you want column names? &amp;nbsp;If so then query sashelp.vcolumns, or dictionary.columns:&lt;BR /&gt;data want; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; set sashelp.vcolumn (where=(libname="WORK" and memname="YOURDATASET"));&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the values in the coulmns then you can use a generic reference:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  gep=sum(of salary:);
run;&lt;/PRE&gt;
&lt;P&gt;However all that aside, its really not a good idea to name your variables with "data" - in this case a date. &amp;nbsp;You could end up with lots of variables, and your code will become difficult to work with as the strcuture changes, and even within a datarow may not be the same. &amp;nbsp;Far better to work with normalised data&amp;amp;colon;&lt;/P&gt;
&lt;P&gt;NAME &amp;nbsp; SURNAME &amp;nbsp;ADDRESS &amp;nbsp;SALARY_DATE &amp;nbsp;SALARY&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;Do remember the data you program on does not need to be the same as output data, you can always transpose at the end.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2016 13:10:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subset-dataset-by-variable-name/m-p/266357#M52486</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-26T13:10:14Z</dc:date>
    </item>
    <item>
      <title>Re: subset dataset by variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subset-dataset-by-variable-name/m-p/266369#M52487</link>
      <description>&lt;P&gt;Hi RW9,&lt;/P&gt;&lt;P&gt;sorry, my explanation was not clear. I would like to get the following;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql; create table subset as select name, Salary201401 .... Salary201512 from input; run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;basically I wanna select all the variables containing "salary" plus something else.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2016 13:48:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subset-dataset-by-variable-name/m-p/266369#M52487</guid>
      <dc:creator>Sir_Highbury</dc:creator>
      <dc:date>2016-04-26T13:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: subset dataset by variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subset-dataset-by-variable-name/m-p/266373#M52488</link>
      <description>&lt;P&gt;Yes, then my first example would be the one:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  select NAME
  into    :VLIST separated by ","
  from   DICTIONARY.COLUMNS
  where LIBNAME="WORK"
    and  MEMNAME="YOURDATASET"
    and  (NAME="NAME" or upcase(substr(NAME,1,6))="SALARY";
quit;

proc sql;
  select  &amp;amp;VLIST.
  from    HAVE:
quit; 
   &lt;/PRE&gt;
&lt;P&gt;However, I will point out again, that this is very symptomatic of the datastructure you have chosen. &amp;nbsp;In a normalised data structure your dataset's strcuture does not change, hence you can avoid all these types of problems, and work on processing data, rather than faffing about trying to work out what the structure of your data is.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2016 13:53:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subset-dataset-by-variable-name/m-p/266373#M52488</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-04-26T13:53:58Z</dc:date>
    </item>
    <item>
      <title>Re: subset dataset by variable name</title>
      <link>https://communities.sas.com/t5/SAS-Programming/subset-dataset-by-variable-name/m-p/266378#M52489</link>
      <description>&lt;P&gt;You can use the colon operator which will keep all variables starting with the prefix indicated.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data want;
Set have;
Keep name salary:;
Run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Conversely, if your keeping almost all of the variables you can drop the ones you don't need instead.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2016 14:00:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/subset-dataset-by-variable-name/m-p/266378#M52489</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-26T14:00:28Z</dc:date>
    </item>
  </channel>
</rss>

