<?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: Selecting multiple variables with a numbered suffix in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Selecting-multiple-variables-with-a-numbered-suffix/m-p/492444#M129405</link>
    <description>&lt;P&gt;Unfortunately not in SQL without macro code. This can be easily accomplished in a SAS data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html&lt;/A&gt;&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 vara1-vara5 varb1-varb5;

*keep vara: varb:;

*keep vara1--varb5;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/150111"&gt;@x2PSx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to select multiple variables with the same prefix but a different numbered suffix in an SQL procedure within SAS Base. I should mention that I need this because the number of variables may change over time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example I want this output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table WANT as
select VARA1, VARA2, VARA3, VARA4, VARA5, VARB1, VARB2, VARB3, VARB4, VARB5
from HAVE;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like my code to be structured like this to select VARA1 to VARA5 and VARB1 to VARB5, is that possible?:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table WANT as
select VARA[*], VARB[*] 
from HAVE;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you so much,&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 04 Sep 2018 19:23:56 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-09-04T19:23:56Z</dc:date>
    <item>
      <title>Selecting multiple variables with a numbered suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-multiple-variables-with-a-numbered-suffix/m-p/492440#M129404</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to select multiple variables with the same prefix but a different numbered suffix in an SQL procedure within SAS Base. I should mention that I need this because the number of variables may change over time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example I want this output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table WANT as
select VARA1, VARA2, VARA3, VARA4, VARA5, VARB1, VARB2, VARB3, VARB4, VARB5
from HAVE;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like my code to be structured like this to select VARA1 to VARA5 and VARB1 to VARB5, is that possible?:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table WANT as
select VARA[*], VARB[*] 
from HAVE;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thank you so much,&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 19:17:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-multiple-variables-with-a-numbered-suffix/m-p/492440#M129404</guid>
      <dc:creator>x2PSx</dc:creator>
      <dc:date>2018-09-04T19:17:39Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting multiple variables with a numbered suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-multiple-variables-with-a-numbered-suffix/m-p/492444#M129405</link>
      <description>&lt;P&gt;Unfortunately not in SQL without macro code. This can be easily accomplished in a SAS data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html&lt;/A&gt;&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 vara1-vara5 varb1-varb5;

*keep vara: varb:;

*keep vara1--varb5;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/150111"&gt;@x2PSx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to select multiple variables with the same prefix but a different numbered suffix in an SQL procedure within SAS Base. I should mention that I need this because the number of variables may change over time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example I want this output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table WANT as
select VARA1, VARA2, VARA3, VARA4, VARA5, VARB1, VARB2, VARB3, VARB4, VARB5
from HAVE;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like my code to be structured like this to select VARA1 to VARA5 and VARB1 to VARB5, is that possible?:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table WANT as
select VARA[*], VARB[*] 
from HAVE;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you so much,&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 19:23:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-multiple-variables-with-a-numbered-suffix/m-p/492444#M129405</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-04T19:23:56Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting multiple variables with a numbered suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-multiple-variables-with-a-numbered-suffix/m-p/492464#M129413</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/150111"&gt;@x2PSx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to select multiple variables with the same prefix but a different numbered suffix in an SQL procedure within SAS Base. I should mention that I need this because the number of variables may change over time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example I want this output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table WANT as
select VARA1, VARA2, VARA3, VARA4, VARA5, VARB1, VARB2, VARB3, VARB4, VARB5
from HAVE;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like my code to be structured like this to select VARA1 to VARA5 and VARB1 to VARB5, is that possible?:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table WANT as
select VARA[*], VARB[*] 
from HAVE;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thank you so much,&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If your VARA VARB are pairs of data , such as purchase/ sale, count/percent or similar taken at different times or places then you might be better off normalizing the data such that you have another variable to indicate the time period or place or whatever that is being hidden in the VARA and VARB suffix and on one record per pair. When that is done then you do not need to keep adjusting code to select or following variables by name. Instead select values of the identification variable and likely BY group processing or use of the identification variable&amp;nbsp;simplifies other code.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 19:57:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-multiple-variables-with-a-numbered-suffix/m-p/492464#M129413</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-09-04T19:57:45Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting multiple variables with a numbered suffix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-multiple-variables-with-a-numbered-suffix/m-p/492480#M129416</link>
      <description>&lt;P&gt;Use KEEP= dataset option instead. Then you can use variable lists.&amp;nbsp; You will not have control over the order of the variables however, they will keep their relative order from the source dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table WANT as
  select *
  from HAVE(keep=vara1-vara5 varb1-varb5)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Sep 2018 20:40:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-multiple-variables-with-a-numbered-suffix/m-p/492480#M129416</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-09-04T20:40:09Z</dc:date>
    </item>
  </channel>
</rss>

