<?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 ALTERNATE COLUMNS. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SELECTING-ALTERNATE-COLUMNS/m-p/927478#M364985</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/436607"&gt;@Discaboota&lt;/a&gt;,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/436607"&gt;@Discaboota&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;I am trying to select alternate columns from my dataset, starting from column number 1 and including every &lt;STRONG&gt;n&lt;/STRONG&gt;th alternate column after that. &lt;BR /&gt;For example, I want to select columns 1, 3, 5, 7, and so on up to column &lt;STRONG&gt;n&lt;/STRONG&gt;. &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;To distinguish between the first and the second "&lt;STRONG&gt;n&lt;/STRONG&gt;", let's say we're going to select every &lt;STRONG&gt;&lt;EM&gt;k&lt;/EM&gt;&lt;/STRONG&gt;th variable (starting from the first) up to the &lt;EM&gt;&lt;STRONG&gt;n&lt;/STRONG&gt;&lt;/EM&gt;th.&lt;/P&gt;
&lt;P&gt;Examples of variable numbers to be selected:&lt;/P&gt;
&lt;PRE&gt;1, 3, 5, 7, 9, 11 (k=2, n=11 or 12)
1, 4, 7, 10, 13 (k=3, n=13, 14 or 15)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code:&lt;/P&gt;
&lt;PRE&gt;%let k=2;
%let n=13;

/* Create list of first, (k+1)-th, (2k+1)-th, ... variable name up to the nth */

proc sql noprint;
select nliteral(name) into :varlist separated by ' '
from dictionary.columns
where libname='&lt;EM&gt;YOURLIB&lt;/EM&gt;' &amp;amp; memname='&lt;EM&gt;HAVE&lt;/EM&gt;' &amp;amp; mod(varnum,&amp;amp;k)=1 &amp;amp; varnum&amp;lt;=&amp;amp;n;
quit;

/* Select variables from the prepared list */

data want;
set &lt;EM&gt;yourlib&lt;/EM&gt;.&lt;EM&gt;have&lt;/EM&gt;(keep=&amp;amp;varlist);
run;&lt;/PRE&gt;
&lt;P&gt;Replace "&lt;EM&gt;&lt;FONT face="courier new,courier"&gt;YOURLIB&lt;/FONT&gt;&lt;/EM&gt;" and "&lt;FONT face="courier new,courier"&gt;&lt;EM&gt;HAVE&lt;/EM&gt;&lt;/FONT&gt;" with your libref and dataset name (using upper case in the WHERE clause). Make sure that the length of the list of variable names doesn't exceed the maximum length specified in &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n1eqbq8qk42fz5n14v229azkoil6.htm" target="_blank" rel="noopener"&gt;system option MVARSIZE&lt;/A&gt; (typically 65534 bytes).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 08 May 2024 08:08:30 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2024-05-08T08:08:30Z</dc:date>
    <item>
      <title>SELECTING ALTERNATE COLUMNS.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SELECTING-ALTERNATE-COLUMNS/m-p/927400#M364984</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hello everyone, I am trying to select alternate columns from my dataset, starting from column number 1 and including every nth alternate column after that. &lt;BR /&gt;For example, I want to select columns 1, 3, 5, 7, and so on up to column n. &lt;BR /&gt;Is there a way to make this selection without having to manually specify the column names?&lt;BR /&gt;Here are my column headers: &lt;BR /&gt;FINAL_STATUS_01MAY24, FINAL_STATUS_02MAY24, and so on... &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I would appreciate any help or advice. Thank you!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2024 07:09:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SELECTING-ALTERNATE-COLUMNS/m-p/927400#M364984</guid>
      <dc:creator>Discaboota</dc:creator>
      <dc:date>2024-05-08T07:09:54Z</dc:date>
    </item>
    <item>
      <title>Re: SELECTING ALTERNATE COLUMNS.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SELECTING-ALTERNATE-COLUMNS/m-p/927478#M364985</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/436607"&gt;@Discaboota&lt;/a&gt;,&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/436607"&gt;@Discaboota&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;I am trying to select alternate columns from my dataset, starting from column number 1 and including every &lt;STRONG&gt;n&lt;/STRONG&gt;th alternate column after that. &lt;BR /&gt;For example, I want to select columns 1, 3, 5, 7, and so on up to column &lt;STRONG&gt;n&lt;/STRONG&gt;. &lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;To distinguish between the first and the second "&lt;STRONG&gt;n&lt;/STRONG&gt;", let's say we're going to select every &lt;STRONG&gt;&lt;EM&gt;k&lt;/EM&gt;&lt;/STRONG&gt;th variable (starting from the first) up to the &lt;EM&gt;&lt;STRONG&gt;n&lt;/STRONG&gt;&lt;/EM&gt;th.&lt;/P&gt;
&lt;P&gt;Examples of variable numbers to be selected:&lt;/P&gt;
&lt;PRE&gt;1, 3, 5, 7, 9, 11 (k=2, n=11 or 12)
1, 4, 7, 10, 13 (k=3, n=13, 14 or 15)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code:&lt;/P&gt;
&lt;PRE&gt;%let k=2;
%let n=13;

/* Create list of first, (k+1)-th, (2k+1)-th, ... variable name up to the nth */

proc sql noprint;
select nliteral(name) into :varlist separated by ' '
from dictionary.columns
where libname='&lt;EM&gt;YOURLIB&lt;/EM&gt;' &amp;amp; memname='&lt;EM&gt;HAVE&lt;/EM&gt;' &amp;amp; mod(varnum,&amp;amp;k)=1 &amp;amp; varnum&amp;lt;=&amp;amp;n;
quit;

/* Select variables from the prepared list */

data want;
set &lt;EM&gt;yourlib&lt;/EM&gt;.&lt;EM&gt;have&lt;/EM&gt;(keep=&amp;amp;varlist);
run;&lt;/PRE&gt;
&lt;P&gt;Replace "&lt;EM&gt;&lt;FONT face="courier new,courier"&gt;YOURLIB&lt;/FONT&gt;&lt;/EM&gt;" and "&lt;FONT face="courier new,courier"&gt;&lt;EM&gt;HAVE&lt;/EM&gt;&lt;/FONT&gt;" with your libref and dataset name (using upper case in the WHERE clause). Make sure that the length of the list of variable names doesn't exceed the maximum length specified in &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n1eqbq8qk42fz5n14v229azkoil6.htm" target="_blank" rel="noopener"&gt;system option MVARSIZE&lt;/A&gt; (typically 65534 bytes).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2024 08:08:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SELECTING-ALTERNATE-COLUMNS/m-p/927478#M364985</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-05-08T08:08:30Z</dc:date>
    </item>
    <item>
      <title>Re: SELECTING ALTERNATE COLUMNS.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SELECTING-ALTERNATE-COLUMNS/m-p/927494#M364990</link>
      <description>&lt;P&gt;No need to ask the same question twice.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; has already given you a very good answer in &lt;A href="https://communities.sas.com/t5/SAS-Programming/I-want-to-select-alternate-columns-in-my-data-set/m-p/927300#M364943" target="_self"&gt;your other thread&lt;/A&gt;. Also, no need to type your subject in ALL CAPITAL LETTERS.&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2024 09:57:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SELECTING-ALTERNATE-COLUMNS/m-p/927494#M364990</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-05-08T09:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: SELECTING ALTERNATE COLUMNS.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SELECTING-ALTERNATE-COLUMNS/m-p/927557#M365005</link>
      <description>&lt;P&gt;Since your other post indicating this process has to deal with additional columns, which is a stupid way to deal with data as code needs to be modified one way or another for almost any step where the variable names keep changing, perhaps&amp;nbsp; you should READ YOUR DATA into a proper format to begin with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Preventing problems is usually way easier than fixing them with cumbersome code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This for example reads 5 pairs of variables into a "long" format with on observation per "date". Your implication from your previous and this post is that the poorly designed data contains sequential date values. So this read such.&lt;/P&gt;
&lt;PRE&gt;data example;
  input id @@;
  do date= '01May2024'd to '05May2024'd;
    input final due @@;
    output;
   end;
  format date date9.;
datalines;
1  2 3 4 5 6 7 8 9 10 11
;&lt;/PRE&gt;
&lt;P&gt;I strongly suspect you are starting with some spreadsheet file and don't realize the problems that many people create by the structures such as yours. SAVE the file to CSV, and an infile statement pointing that file and update the values of "date" in the do loop and you may be able to read this into a much more flexible data set:&lt;/P&gt;
&lt;PRE&gt;data example;
  infile "C:\somepath\file.csv"  dlm=',' dsd ;
  input id @@;  /* other variables before the date named columns go here*/
  do date= '01May2024'd to '05May2024'd;
     input final due @@;
     output;
  end;
  format date date9.;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2024 15:43:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SELECTING-ALTERNATE-COLUMNS/m-p/927557#M365005</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-05-08T15:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: SELECTING ALTERNATE COLUMNS.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SELECTING-ALTERNATE-COLUMNS/m-p/928935#M365513</link>
      <description>&lt;P&gt;Then it is SAS/IML thing.&lt;/P&gt;
&lt;P&gt;If these variables are&amp;nbsp; all numeric or character&amp;nbsp; type ,you could try this one :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.heart(obs=10);
 keep _numeric_;
run;


proc iml;
use have;
read all var _all_ into x[c=vname];&lt;BR /&gt;close;&lt;BR /&gt;
idx=do(1,ncol(x),2);
want=x[,idx];

/*Save these desired columns into a dataset named 'WANT'*/
create want from want[c=(vname[idx])];
append from want;
close;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 19 May 2024 02:44:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SELECTING-ALTERNATE-COLUMNS/m-p/928935#M365513</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-05-19T02:44:08Z</dc:date>
    </item>
  </channel>
</rss>

