<?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 keep variable which has similar variable names in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-variable-which-has-similar-variable-names/m-p/821096#M324157</link>
    <description>&lt;P&gt;One way is to use the dictionary tables to select the variables you want&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;demo:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let names=;
PROC SQL;/*libname and memname for consultation purpose only*/
   SELECT libname, memname, name INTO :lib,:mem,:names SEPARATED BY ' ,'
   FROM sashelp.vcolumn
   WHERE libname EQ upper('sashelp')
   AND memname   EQ upper('geoexm')
   AND name LIKE upper('name%')
   ;
QUIT;
%symdel lib mem;
%put &amp;amp;=names;

PROC SQL outobs=10/*limit results to 10 observations*/;
   SELECT &amp;amp;names.
   FROM sashelp.geoexm
   ;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Adapt the code to your requirements.&lt;/P&gt;</description>
    <pubDate>Thu, 30 Jun 2022 10:08:02 GMT</pubDate>
    <dc:creator>Oligolas</dc:creator>
    <dc:date>2022-06-30T10:08:02Z</dc:date>
    <item>
      <title>How to keep variable which has similar variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-variable-which-has-similar-variable-names/m-p/821092#M324155</link>
      <description>&lt;P&gt;If data has variables name1,name2 name3...and so on which I want to keep in the data which giving individual names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in data step i could manage by adding colon but how can I manage in proc sql (need query for this)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data a1;&lt;BR /&gt;set abc;&lt;BR /&gt;keep number name&lt;STRONG&gt;&lt;FONT face="impact,chicago"&gt;:&lt;/FONT&gt;&lt;/STRONG&gt; ;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 09:52:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-variable-which-has-similar-variable-names/m-p/821092#M324155</guid>
      <dc:creator>pdhokriya</dc:creator>
      <dc:date>2022-06-30T09:52:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep variable which has similar variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-variable-which-has-similar-variable-names/m-p/821095#M324156</link>
      <description>&lt;P&gt;In SQL, you have to type each variable name. Or have a macro variable that contains each variable name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
    /* Create macro variable named &amp;amp;VARNAMES by using SQL */
    select distinct name into :varnames separated by ',' from dictionary.columns
    where libname='WORK' and memname='ABC' and name eqt 'NAME';
quit;

proc sql;
    /* Create table A1 using the list of variable names found above */
    create table a1 as select number,&amp;amp;varnames from abc;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Jun 2022 12:28:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-variable-which-has-similar-variable-names/m-p/821095#M324156</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-30T12:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep variable which has similar variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-variable-which-has-similar-variable-names/m-p/821096#M324157</link>
      <description>&lt;P&gt;One way is to use the dictionary tables to select the variables you want&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;demo:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let names=;
PROC SQL;/*libname and memname for consultation purpose only*/
   SELECT libname, memname, name INTO :lib,:mem,:names SEPARATED BY ' ,'
   FROM sashelp.vcolumn
   WHERE libname EQ upper('sashelp')
   AND memname   EQ upper('geoexm')
   AND name LIKE upper('name%')
   ;
QUIT;
%symdel lib mem;
%put &amp;amp;=names;

PROC SQL outobs=10/*limit results to 10 observations*/;
   SELECT &amp;amp;names.
   FROM sashelp.geoexm
   ;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Adapt the code to your requirements.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 10:08:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-variable-which-has-similar-variable-names/m-p/821096#M324157</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2022-06-30T10:08:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to keep variable which has similar variable names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-keep-variable-which-has-similar-variable-names/m-p/821117#M324166</link>
      <description>&lt;P&gt;In SQL you have to list all of the variables explicitly, although you can use * to select ALL of the variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could use code generation (such as putting the list into a macro variable and using the macro variable's value as part of the SQL statement).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or in this specific case you could use SAS dataset option KEEP= instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table a1 as
select * 
  from abc (keep=number name:)
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2022 12:29:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-keep-variable-which-has-similar-variable-names/m-p/821117#M324166</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-30T12:29:47Z</dc:date>
    </item>
  </channel>
</rss>

