<?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: Select variables  dataset in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-variables-dataset/m-p/910160#M44120</link>
    <description>&lt;P&gt;Explain more about how the data is structured.&amp;nbsp; Why do you have dates stored in the NAME of the variable.&amp;nbsp; It is best to store data in the VALUE of a variable instead.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a variable (or set of variables) that uniquely identify the observations in your dataset perhaps you should first transpose the data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=tall;
  by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can select the observations from the TALL dataset what came from variables that had a particular pattern to their names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set tall;
  where _name_ like '%^_20230612' escape '^' ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you really want to perpetuate the problem of having dates in variable names you could build a list of variable names into a macro variable&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select nliteral(name) into :varlist separated by ' '
 from dictionary.columns
 where libname='WORK' and memname='HAVE'
   and name like '%^_20230612' escape '^'
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and use the macro variable to generate part of the code to select the variables of interest.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  keep id &amp;amp;varlist;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 02 Jan 2024 20:39:50 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-01-02T20:39:50Z</dc:date>
    <item>
      <title>Select variables  dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-variables-dataset/m-p/910148#M44119</link>
      <description>I have many variables in a database by date: 

Name variables: 
XXXX_20220101 YYYY_20220101 ZZZZ_20220101 WWWW_20220101 
XXXX_20220202 YYYY_20220202 ZZZZ_20220202 WWWW_20220202
XXXX_20220303 YYYY_20220303 ZZZZ_20220303 WWWW_20220303 ...

I want to select all the variables of a date in a new database. How do I do it?

where scan(all,-1,'_') = 20230612;</description>
      <pubDate>Tue, 02 Jan 2024 20:16:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-variables-dataset/m-p/910148#M44119</guid>
      <dc:creator>Thalitacosta</dc:creator>
      <dc:date>2024-01-02T20:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: Select variables  dataset</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-variables-dataset/m-p/910160#M44120</link>
      <description>&lt;P&gt;Explain more about how the data is structured.&amp;nbsp; Why do you have dates stored in the NAME of the variable.&amp;nbsp; It is best to store data in the VALUE of a variable instead.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a variable (or set of variables) that uniquely identify the observations in your dataset perhaps you should first transpose the data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=tall;
  by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can select the observations from the TALL dataset what came from variables that had a particular pattern to their names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set tall;
  where _name_ like '%^_20230612' escape '^' ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you really want to perpetuate the problem of having dates in variable names you could build a list of variable names into a macro variable&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select nliteral(name) into :varlist separated by ' '
 from dictionary.columns
 where libname='WORK' and memname='HAVE'
   and name like '%^_20230612' escape '^'
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and use the macro variable to generate part of the code to select the variables of interest.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  keep id &amp;amp;varlist;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 Jan 2024 20:39:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Select-variables-dataset/m-p/910160#M44120</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-01-02T20:39:50Z</dc:date>
    </item>
  </channel>
</rss>

