<?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 Help me please with a loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-me-please-with-a-loop/m-p/693057#M211263</link>
    <description>&lt;P&gt;Hello everybody,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm new to programming in SAS, I ever use R and Python. In these language I can applied a LOOP for move&amp;nbsp;through rows of column in data frame and reference a column in data frame so: "df$variable[1]" or "df.variable [1]".&amp;nbsp;I want to do the same in SAS to generate a new table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could someone give me an idea? Please&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry about my grammar, I'm not very good at writing in English&lt;/P&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;&lt;P&gt;&amp;nbsp;&lt;/P&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, 21 Oct 2020 02:38:45 GMT</pubDate>
    <dc:creator>irparedesr</dc:creator>
    <dc:date>2020-10-21T02:38:45Z</dc:date>
    <item>
      <title>Help me please with a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-me-please-with-a-loop/m-p/693057#M211263</link>
      <description>&lt;P&gt;Hello everybody,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm new to programming in SAS, I ever use R and Python. In these language I can applied a LOOP for move&amp;nbsp;through rows of column in data frame and reference a column in data frame so: "df$variable[1]" or "df.variable [1]".&amp;nbsp;I want to do the same in SAS to generate a new table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could someone give me an idea? Please&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry about my grammar, I'm not very good at writing in English&lt;/P&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;&lt;P&gt;&amp;nbsp;&lt;/P&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, 21 Oct 2020 02:38:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-me-please-with-a-loop/m-p/693057#M211263</guid>
      <dc:creator>irparedesr</dc:creator>
      <dc:date>2020-10-21T02:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: Help me please with a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-me-please-with-a-loop/m-p/693060#M211265</link>
      <description>&lt;P&gt;Sorry, your goal is unclear. What do you do with that referenced column? What are you trying to achieve?&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 03:13:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-me-please-with-a-loop/m-p/693060#M211265</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-10-21T03:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: Help me please with a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-me-please-with-a-loop/m-p/693063#M211268</link>
      <description>&lt;P&gt;Welcome to the SAS Community.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a new SAS user, I think it would be well worth your while to check out some of the training videos available here:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/New-SAS-User/bd-p/new-users" target="_blank"&gt;https://communities.sas.com/t5/New-SAS-User/bd-p/new-users&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 03:49:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-me-please-with-a-loop/m-p/693063#M211268</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-10-21T03:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: Help me please with a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-me-please-with-a-loop/m-p/693067#M211272</link>
      <description>&lt;P&gt;SAS does not work in a similar fashion as R or Python. It processes data line by line instead so each data step is an implicit loop by default. This is historically advantageous as it didn't matter how big your data set was, it simply went through it line by line. In comparison, R/Python typically default to in memory operations, which require loading ALL your data into memory.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would recommend taking the &lt;A href="https://www.sas.com/en_ca/training/offers/free-training.html" target="_self"&gt;free SAS e-courses&lt;/A&gt; if you're trying to learn SAS. There's also a variation on Coursera that you could use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Arrays are one usage of loops but likely beyond you at the moment.&lt;/P&gt;
&lt;P&gt;Here's a tutorial on using Arrays in SAS&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-arrays/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-arrays/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To create a data set you can just type out the data usually, unless you have a complicated structure?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data demo;
input ID $ var1 - var4;
cards;
A 1 2 3 4
B 5 6 7 8
C 8 9 10 11
;;;;
run;&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;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/352815"&gt;@irparedesr&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello everybody,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm new to programming in SAS, I ever use R and Python. In these language I can applied a LOOP for move&amp;nbsp;through rows of column in data frame and reference a column in data frame so: "df$variable[1]" or "df.variable [1]".&amp;nbsp;I want to do the same in SAS to generate a new table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could someone give me an idea? Please&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry about my grammar, I'm not very good at writing in English&lt;/P&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;
&lt;P&gt;&amp;nbsp;&lt;/P&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;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 04:15:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-me-please-with-a-loop/m-p/693067#M211272</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-21T04:15:07Z</dc:date>
    </item>
    <item>
      <title>Re: Help me please with a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-me-please-with-a-loop/m-p/693075#M211277</link>
      <description>&lt;P&gt;A group of variables, of the &lt;STRONG&gt;same type&lt;/STRONG&gt;, would be called an ARRAY. Arrays a basically only available in the data step and the definition does not persist after the data step executes. The array only operates on one observation (record or row) at a time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a data step you define an array using the Array statement and options.&lt;/P&gt;
&lt;P&gt;basic definition of an array for numeric values looks like:&lt;/P&gt;
&lt;PRE&gt;array somename (*) var1 var2 var3 ;&lt;/PRE&gt;
&lt;P&gt;If the variable already exists it will be used, and if it doesn't then a new variable with the name is created.&lt;/P&gt;
&lt;P&gt;If creating new variables of character type you need to provide a $ to indicate the variables are character and a length:&lt;/P&gt;
&lt;PRE&gt;array something (*) $ 15 var10 var11 var12;&lt;/PRE&gt;
&lt;P&gt;You can make new variables with a numeric suffix like this. Character variables would again require the $ and length.&lt;/P&gt;
&lt;PRE&gt;array other (3);&lt;/PRE&gt;
&lt;P&gt;Would create three variables named other1 other2 and other3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The easiest way to use the values in an array is an iterated loop such as&lt;/P&gt;
&lt;PRE&gt;do i = 1 to dim(other);
    other[i] = rand('uniform');
end;&lt;/PRE&gt;
&lt;P&gt;You use the index, the loop counter, to reference the elements of the array as they appear on the ARRAY statement. You can use ( ) instead of [ ] to enclose the index indicator but I find that in long lines of code it makes it easier to keep track of the index with the square brackets. The index value has to be in the range defined by the array statement. The index values must be sequential.&lt;/P&gt;
&lt;P&gt;Advanced topics: Indices that start with a value other than 1, 2 or more dimension arrays.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are quite a few functions that will use the whole value of the array by using the syntax (of arrayname(*) ) so that you do not have to actually loop over all the values explicitly.&lt;/P&gt;
&lt;P&gt;The data step statistics functions like Sum, Mean, N, Nmiss and so on will use this syntax:&lt;/P&gt;
&lt;PRE&gt;Total = sum(of arrayname(*) )&lt;/PRE&gt;
&lt;P&gt;Many of the functions that accept varying length of variable or value lists will do this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also use functions or operations that return 1) integer values 2) in the range of the index to reference elements of the array.&lt;/P&gt;
&lt;PRE&gt;value = other [ i + 1];&lt;/PRE&gt;
&lt;P&gt;for example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this is not sufficient to get you started please provide some example data of what you have in the form of a data step and what the result should look like. Example:&lt;/P&gt;
&lt;PRE&gt;data have;
    input x y z;
datalines;
1 2 3
1 3 17
2 2 12
;&lt;/PRE&gt;
&lt;P&gt;Please paste any data step into a code box opened on the forum by using the &amp;lt;/&amp;gt; icon. This is important because this forum otherwise &lt;STRONG&gt;will&lt;/STRONG&gt; reformat text and may do so in a way that will prevent the data step from running. Please test your data step code before posting to make sure that it runs correctly.&lt;/P&gt;
&lt;P&gt;If you actual problem involves many variables please use fewer to demonstrate the issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 06:14:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-me-please-with-a-loop/m-p/693075#M211277</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-21T06:14:30Z</dc:date>
    </item>
    <item>
      <title>LRe: Help me please with a loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-me-please-with-a-loop/m-p/693123#M211303</link>
      <description>&lt;P&gt;Then you need to learn SAS/IML . Calling&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or if it is simple operation on columns,try PROC SQL&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 12:17:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-me-please-with-a-loop/m-p/693123#M211303</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-10-21T12:17:03Z</dc:date>
    </item>
  </channel>
</rss>

