<?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 Indexing Variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Indexing-Variables/m-p/527474#M143807</link>
    <description>&lt;P&gt;Hello SAS community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to SAS programming. I have a data set with say, 20 variables. Suppose that I want to set up a one-to-one correspondence between these variables and variables called x_1, x_2,...,x_20. I have more of a mathematical background and find it is much easier to perform calculations and other procedures when we refer to the ith variable as x_i rather than ith-variable-name, which in my view streamlines subsequent programming. From what I understand, these data sets are essentially matrices, in something like MATLAB one can specify a column (variable) simply as x(:,j), this is where my intuition is coming from, however I am struggling to&amp;nbsp;find similar analogies in&amp;nbsp;SAS. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a straight forward&amp;nbsp;way to map&amp;nbsp;k non-indexed variables {var,bar,car,....,zar} to {x1,x2,...,xk} and back again?&lt;/P&gt;&lt;P&gt;Another question: Does there exist a function which I can apply to a data set which returns the number of variables?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for taking the time to read this&lt;/P&gt;</description>
    <pubDate>Tue, 15 Jan 2019 19:39:16 GMT</pubDate>
    <dc:creator>Jack_Sabbath</dc:creator>
    <dc:date>2019-01-15T19:39:16Z</dc:date>
    <item>
      <title>Indexing Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Indexing-Variables/m-p/527474#M143807</link>
      <description>&lt;P&gt;Hello SAS community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to SAS programming. I have a data set with say, 20 variables. Suppose that I want to set up a one-to-one correspondence between these variables and variables called x_1, x_2,...,x_20. I have more of a mathematical background and find it is much easier to perform calculations and other procedures when we refer to the ith variable as x_i rather than ith-variable-name, which in my view streamlines subsequent programming. From what I understand, these data sets are essentially matrices, in something like MATLAB one can specify a column (variable) simply as x(:,j), this is where my intuition is coming from, however I am struggling to&amp;nbsp;find similar analogies in&amp;nbsp;SAS. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a straight forward&amp;nbsp;way to map&amp;nbsp;k non-indexed variables {var,bar,car,....,zar} to {x1,x2,...,xk} and back again?&lt;/P&gt;&lt;P&gt;Another question: Does there exist a function which I can apply to a data set which returns the number of variables?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for taking the time to read this&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 19:39:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Indexing-Variables/m-p/527474#M143807</guid>
      <dc:creator>Jack_Sabbath</dc:creator>
      <dc:date>2019-01-15T19:39:16Z</dc:date>
    </item>
    <item>
      <title>Re: Indexing Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Indexing-Variables/m-p/527480#M143811</link>
      <description>&lt;P&gt;It sounds like arrays will help you a lot..&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
array x{*} var bar car zar;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the code above, x[1]=var, x[2]=bar and so on.. Here, I assume that var, bar, bar and zar are all same-type variables, ie. either all character or all numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In regards to your last question&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
nvars=attrn(open("sashelp.class"),"NVARS"); 
put nvars;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 20:05:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Indexing-Variables/m-p/527480#M143811</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-15T20:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: Indexing Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Indexing-Variables/m-p/527491#M143814</link>
      <description>&lt;P&gt;You need to explain what you are trying to do to see if there are easier ways to do it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example there might not be any need to create meaningful names for the variables if you don't need them.&amp;nbsp; Just name the variables var1, var2, var3, etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you might have made a wide format data set say with by week measures (week1, week2, week3, ...) when really your data is more naturally modeled as two variable (Week, Value) and multiple observations.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 20:38:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Indexing-Variables/m-p/527491#M143814</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-01-15T20:38:02Z</dc:date>
    </item>
    <item>
      <title>Re: Indexing Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Indexing-Variables/m-p/527509#M143823</link>
      <description>&lt;P&gt;My apologies for not making my problem clearer. Suppose that I would like to perform logistic regression on some variables in a data set. Ideally I would like to avoid the brute force method of typing each variable individually. I am following the method described in the following blog post: &lt;A href="https://blogs.sas.com/content/iml/2017/02/13/run-1000-regressions.html" target="_blank"&gt;&lt;FONT color="#0000ff" face="Calibri" size="3"&gt;https://blogs.sas.com/content/iml/2017/02/13/run-1000-regressions.html&lt;/FONT&gt;&lt;/A&gt;. Now, the variables which I am considering do not have the convenient names x1,x2,..,xk as in the blog post, they have names like 'aar', 'bar', 'car'... ect. Suppose, for example, I would like to drop the first 5 variables without explicitly writing a drop statement identifying the names of these variables. Instead, I would prefer to write something in the spirit of "drop x1-x5" as the position the variable in the list&amp;nbsp;is what is of interest to me. Moreover, I would also prefer to not have to explicitly type in the explicit name of the variables when defining the array. I would like to take the variables in the data set and feed them into an array or even a copy of the original data set with the variables renamed to x1 to xk, where k is the number of variables.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 21:06:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Indexing-Variables/m-p/527509#M143823</guid>
      <dc:creator>Jack_Sabbath</dc:creator>
      <dc:date>2019-01-15T21:06:26Z</dc:date>
    </item>
    <item>
      <title>Re: Indexing Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Indexing-Variables/m-p/527576#M143843</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/249653"&gt;@Jack_Sabbath&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;My apologies for not making my problem clearer. Suppose that I would like to perform logistic regression on some variables in a data set. Ideally I would like to avoid the brute force method of typing each variable individually. I am following the method described in the following blog post: &lt;A href="https://blogs.sas.com/content/iml/2017/02/13/run-1000-regressions.html" target="_blank"&gt;&lt;FONT color="#0000ff" face="Calibri" size="3"&gt;https://blogs.sas.com/content/iml/2017/02/13/run-1000-regressions.html&lt;/FONT&gt;&lt;/A&gt;. Now, the variables which I am considering do not have the convenient names x1,x2,..,xk as in the blog post, they have names like 'aar', 'bar', 'car'... ect. Suppose, for example, I would like to drop the first 5 variables without explicitly writing a drop statement identifying the names of these variables. Instead, I would prefer to write something in the spirit of "drop x1-x5" as the position the variable in the list&amp;nbsp;is what is of interest to me. Moreover, I would also prefer to not have to explicitly type in the explicit name of the variables when defining the array. I would like to take the variables in the data set and feed them into an array or even a copy of the original data set with the variables renamed to x1 to xk, where k is the number of variables.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would suggest renaming your variables to use the technique in the blog. Either assign a label with the original variable name or use a meaningful label to begin with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 00:33:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Indexing-Variables/m-p/527576#M143843</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-01-16T00:33:04Z</dc:date>
    </item>
    <item>
      <title>Re: Indexing Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Indexing-Variables/m-p/527590#M143853</link>
      <description>&lt;P&gt;The double dash syntax might help you to make arrays perfectly dynamic.&lt;/P&gt;
&lt;P&gt;Consider this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data NEW;
  FIRST_VAR=1;
  set SASHELP.CLASS(obs=1);
  LAST_VAR=1;
  array NUM_VARS[*] FIRST_VAR - numeric   - LAST_VAR;
  array CHR_VARS[*] FIRST_VAR - character - LAST_VAR;
  putlog '***NUM VARS***';
  do I=2 to dim(NUM_VARS)-1;  %* ignore first and last num as they are not in the data set;
    putlog NUM_VARS[I]=;
  end;
  putlog '***CHAR VARS***';
  do I=1 to dim(CHR_VARS);
    putlog CHR_VARS[I]=;
  end;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;***NUM VARS***&lt;BR /&gt;Age=14&lt;BR /&gt;Height=69&lt;BR /&gt;Weight=112.5&lt;BR /&gt;***CHAR VARS***&lt;BR /&gt;Name=Alfred&lt;BR /&gt;Sex=M&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note how the array only picks up variables already in the PDV when defined. Variable &lt;FONT face="courier new,courier"&gt;I&lt;/FONT&gt; is not in the array.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 01:55:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Indexing-Variables/m-p/527590#M143853</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-01-16T01:55:17Z</dc:date>
    </item>
    <item>
      <title>Re: Indexing Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Indexing-Variables/m-p/527629#M143886</link>
      <description>SAS doesn't work that way and if you try to work that way you'll run into some issues. If you really want to wrk that way, you can drop into PROC IML which is more matrix and similar to R or Matlab in that respect. &lt;BR /&gt;&lt;BR /&gt;SAS data steps on the other hand, simply process a single row of data at a time. Think of it as loading a line, doing something, whatever you tell it, then it goes to the next line automatically and processes that line. It doesn't deal with an entire column at the same time as you would expect and you can't use shortcut references to variables or rows in that manner either. Which is why I'd suggest not going down that route.</description>
      <pubDate>Wed, 16 Jan 2019 04:38:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Indexing-Variables/m-p/527629#M143886</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-16T04:38:29Z</dc:date>
    </item>
    <item>
      <title>Re: Indexing Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Indexing-Variables/m-p/527631#M143887</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These are likely helpful for what you're trying to do and will provide some other options:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sastraining/2017/08/29/sas-variable-lists-by-pattern/" target="_blank"&gt;https://blogs.sas.com/content/sastraining/2017/08/29/sas-variable-lists-by-pattern/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sastraining/2011/11/18/jedi-sas-tricks-building-a-name-suffix-variable-list/" target="_blank"&gt;https://blogs.sas.com/content/sastraining/2011/11/18/jedi-sas-tricks-building-a-name-suffix-variable-list/&lt;/A&gt;&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;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2016/01/18/create-macro-list-values.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2016/01/18/create-macro-list-values.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/249653"&gt;@Jack_Sabbath&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;My apologies for not making my problem clearer. Suppose that I would like to perform logistic regression on some variables in a data set. Ideally I would like to avoid the brute force method of typing each variable individually. I am following the method described in the following blog post: &lt;A href="https://blogs.sas.com/content/iml/2017/02/13/run-1000-regressions.html" target="_blank"&gt;&lt;FONT face="Calibri" size="3" color="#0000ff"&gt;https://blogs.sas.com/content/iml/2017/02/13/run-1000-regressions.html&lt;/FONT&gt;&lt;/A&gt;. Now, the variables which I am considering do not have the convenient names x1,x2,..,xk as in the blog post, they have names like 'aar', 'bar', 'car'... ect. Suppose, for example, I would like to drop the first 5 variables without explicitly writing a drop statement identifying the names of these variables. Instead, I would prefer to write something in the spirit of "drop x1-x5" as the position the variable in the list&amp;nbsp;is what is of interest to me. Moreover, I would also prefer to not have to explicitly type in the explicit name of the variables when defining the array. I would like to take the variables in the data set and feed them into an array or even a copy of the original data set with the variables renamed to x1 to xk, where k is the number of variables.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 04:46:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Indexing-Variables/m-p/527631#M143887</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-16T04:46:29Z</dc:date>
    </item>
    <item>
      <title>Re: Indexing Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Indexing-Variables/m-p/527659#M143906</link>
      <description>&lt;P&gt;You gonna learn SAS/IML language ,it is very like Matlab .&lt;/P&gt;
&lt;P&gt;and read&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;blog would give you a lot help .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For your last question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dsid=%sysfunc(open(sashelp.class));
%let nvar=%sysfunc(attrn(&amp;amp;dsid,nvar));
%let dsid=%sysfunc(close(&amp;amp;dsid));

%put nvar= &amp;amp;nvar;&lt;/CODE&gt;&lt;/PRE&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>Wed, 16 Jan 2019 08:49:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Indexing-Variables/m-p/527659#M143906</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-01-16T08:49:22Z</dc:date>
    </item>
  </channel>
</rss>

