<?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: Consecutive DO loops creating the same column value in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Consecutive-DO-loops-creating-the-same-column-value/m-p/572419#M12322</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281086"&gt;@lalapopia&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I don't really follow, isn't delaiFY1 just an integer difference between two dates?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;delaiFY1=intck('month',date,dateFY1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So the first loop goes from 1 to delaiFY1, say it's 6. Then we create vraidate, but change it in the next loop, which goes from 1 to 12.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What happens to vraidate in the second and third loops?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you run code like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  do fred=1 to 5;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You get a dataset with one variable named FRED and five observations where the value of FRED is different in each of them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your example code is doing the exact same thing, only with a more complicated dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The value of VRAIDATE that SAS currently has in memory is changing as the lines of code in the data step execute.&amp;nbsp; But the OUTPUT statement writes a snapshot of the current values when it executes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The variable VRAIDATE is "created" when SAS compiles the logic of the dataset.&amp;nbsp; So the variable is numeric and has a date format attached to it.&amp;nbsp; Its definition does not change while the step runs just because it is referenced in more than one statement.&amp;nbsp; It is the value of VRAIDATE that will vary.&amp;nbsp; That is why they are called variables.&lt;/P&gt;</description>
    <pubDate>Wed, 10 Jul 2019 15:58:30 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-07-10T15:58:30Z</dc:date>
    <item>
      <title>Consecutive DO loops creating the same column value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Consecutive-DO-loops-creating-the-same-column-value/m-p/572391#M12310</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*Little background: I'm currently an intern who was asked to translate a coworker's SAS code to Python. This is the first time I ever read SAS code and my coworker just left for vacation. Unfortunately my company didn't install SAS in my PC, so I can't see the tables produced.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My question: In the code below, there are 3 DO loops, each runs from 1 to a number. Each loop seems to create a column called &lt;FONT color="#FF6600"&gt;vraidate&amp;nbsp;&lt;FONT color="#000000"&gt;and to update the values of a column called&amp;nbsp;&lt;CODE class=" language-sas"&gt;&lt;FONT color="#808000"&gt;deltaEPS&lt;FONT color="#000000"&gt;,&amp;nbsp;however the values assigned to the rows of these columns are different in each loop! What happens to the values of these columns from the first two loops? They don't seem to be used for anything else in the code.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/CODE&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;&lt;FONT color="#000000"&gt;&lt;CODE class=" language-sas"&gt;&lt;FONT color="#808000"&gt;&lt;FONT color="#000000"&gt;Does the program create a brand new column each time? &lt;/FONT&gt;&lt;/FONT&gt;&lt;/CODE&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;&lt;FONT color="#000000"&gt;&lt;CODE class=" language-sas"&gt;&lt;FONT color="#808000"&gt;&lt;FONT color="#000000"&gt;Finally, the second part of the code assigns one value of &lt;FONT color="#FF6600"&gt;vraidate&lt;/FONT&gt; to the date. Which value is this?&lt;/FONT&gt;&lt;/FONT&gt;&lt;/CODE&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF6600"&gt;&lt;FONT color="#000000"&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;The code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data series2;set moustache;by country_name secteur;if last.Secteur=1;delaiFY1=intck('month',date,dateFY1);
if delaiFY1=. then delete;
 do i=1 to delaiFY1;
&lt;FONT color="#FF6600"&gt; vraidate&lt;/FONT&gt;=intnx('Month',date,i,'end');format vraidate date9.;
 if EPS_FY1_INDEX&amp;lt;=0 then deltaEPS=EPS_12M_TR;else &lt;FONT color="#808000"&gt;deltaEPS&lt;/FONT&gt;=EPS_12M_TR+(i/delaiFY1)*(EPS_FY1_INDEX-EPS_12M_TR);
 output;
 end;
 do j=1 to 12;
 &lt;FONT color="#FF6600"&gt;vraidate&lt;/FONT&gt;=intnx('Month',dateFY1,j,'end');format vraidate date9.;
 if EPS_FY2_INDEX&amp;lt;=0 then deltaEPS=EPS_FY1_INDEX;else &lt;FONT color="#808000"&gt;deltaEPS&lt;/FONT&gt;=EPS_FY1_INDEX+(j/12)*(EPS_FY2_INDEX-EPS_FY1_INDEX);
 output;
 end;
 do k=1 to 12;
 &lt;FONT color="#FF6600"&gt;vraidate&lt;/FONT&gt;=intnx('Month',dateFY2,k,'end');format vraidate date9.;
 if EPS_FY3_INDEX&amp;lt;=0 then deltaEPS=EPS_FY2_INDEX;else &lt;FONT color="#808000"&gt;deltaEPS&lt;/FONT&gt;=EPS_FY2_INDEX+(k/12)*(EPS_FY3_INDEX-EPS_FY2_INDEX);
 output;
 end;run;
 
data series2;set series2;
date=&lt;FONT color="#FF6600"&gt;vraidate&lt;/FONT&gt;;format date date9.;
ProjectionEPS=deltaEPS;
keep country_name Secteur date FY0_ENDDATE ProjectionEPS;
proc sort;by country_name Secteur date;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Jul 2019 15:03:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Consecutive-DO-loops-creating-the-same-column-value/m-p/572391#M12310</guid>
      <dc:creator>lalapopia</dc:creator>
      <dc:date>2019-07-10T15:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive DO loops creating the same column value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Consecutive-DO-loops-creating-the-same-column-value/m-p/572397#M12311</link>
      <description>&lt;P&gt;The OUTPUT statement writes an observation to the output dataset when it runs.&lt;/P&gt;
&lt;P&gt;So this loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i=1 to delaiFY1;
  vraidate=intnx('Month',date,i,'end');
  if EPS_FY1_INDEX&amp;lt;=0 then deltaEPS=EPS_12M_TR;
  else deltaEPS=EPS_12M_TR+(i/delaiFY1)*(EPS_FY1_INDEX-EPS_12M_TR);
  output;
end;
format vraidate date9.;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will output DELIAFY1 observations to the output dataset. Each one will have a different value of VRAIDATE and possibly a different value of DELTAEPS.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 15:09:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Consecutive-DO-loops-creating-the-same-column-value/m-p/572397#M12311</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-10T15:09:52Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive DO loops creating the same column value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Consecutive-DO-loops-creating-the-same-column-value/m-p/572403#M12313</link>
      <description>Do you have the SAS data sets? If so, you can install either the SAS Universal Viewrer to use it and there's is a python package to read a SAS data sets.</description>
      <pubDate>Wed, 10 Jul 2019 15:21:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Consecutive-DO-loops-creating-the-same-column-value/m-p/572403#M12313</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-10T15:21:34Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive DO loops creating the same column value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Consecutive-DO-loops-creating-the-same-column-value/m-p/572405#M12314</link>
      <description>&lt;P&gt;I don't really follow, isn't delaiFY1 just an integer difference between two dates?&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;delaiFY1=intck('month',date,dateFY1);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So the first loop goes from 1 to delaiFY1, say it's 6. Then we create vraidate, but change it in the next loop, which goes from 1 to 12.&amp;nbsp;&lt;/P&gt;&lt;P&gt;What happens to vraidate in the second and third loops?&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 15:22:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Consecutive-DO-loops-creating-the-same-column-value/m-p/572405#M12314</guid>
      <dc:creator>lalapopia</dc:creator>
      <dc:date>2019-07-10T15:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive DO loops creating the same column value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Consecutive-DO-loops-creating-the-same-column-value/m-p/572407#M12316</link>
      <description>No, I only have the code in Notepad, no datasets</description>
      <pubDate>Wed, 10 Jul 2019 15:24:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Consecutive-DO-loops-creating-the-same-column-value/m-p/572407#M12316</guid>
      <dc:creator>lalapopia</dc:creator>
      <dc:date>2019-07-10T15:24:27Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive DO loops creating the same column value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Consecutive-DO-loops-creating-the-same-column-value/m-p/572408#M12317</link>
      <description>&lt;P&gt;If that is the code your coworker wrote then the first thing to do when he/she returns is to beat them severely about the head and shoulders for lousy code structures making it hard to read.&lt;/P&gt;
&lt;P&gt;Reformatting the code for the first data step a bit:&lt;/P&gt;
&lt;PRE&gt;data series2;
set moustache;
by country_name secteur;
if last.Secteur=1;
delaiFY1=intck('month',date,dateFY1);
if delaiFY1=. then delete;
 do i=1 to delaiFY1;
   vraidate=intnx('Month',date,i,'end');
   format vraidate date9.;
   if EPS_FY1_INDEX&amp;lt;=0 then deltaEPS=EPS_12M_TR;
   else deltaEPS=EPS_12M_TR+(i/delaiFY1)*(EPS_FY1_INDEX-EPS_12M_TR);
   &lt;STRONG&gt;&lt;FONT color="#ff00ff"&gt;output;&lt;/FONT&gt;&lt;/STRONG&gt;
 end;
 do j=1 to 12;
   vraidate=intnx('Month',dateFY1,j,'end');
   format vraidate date9.;
   if EPS_FY2_INDEX&amp;lt;=0 then deltaEPS=EPS_FY1_INDEX;
   else deltaEPS=EPS_FY1_INDEX+(j/12)*(EPS_FY2_INDEX-EPS_FY1_INDEX);
   &lt;FONT color="#ff00ff"&gt;&lt;STRONG&gt;output;&lt;/STRONG&gt;&lt;/FONT&gt;
 end;
 do k=1 to 12;
   vraidate=intnx('Month',dateFY2,k,'end');
   format vraidate date9.;
   if EPS_FY3_INDEX&amp;lt;=0 then deltaEPS=EPS_FY2_INDEX;
   else deltaEPS=EPS_FY2_INDEX+(k/12)*(EPS_FY3_INDEX-EPS_FY2_INDEX);
   &lt;FONT color="#ff00ff"&gt;&lt;STRONG&gt;output;&lt;/STRONG&gt;&lt;/FONT&gt;
 end;
run;
 
&lt;/PRE&gt;
&lt;P&gt;The OUTPUT statements tell says to write the current data vector to the data set. So you get a different loop each writing to the same variable. The first line in each do loop is setting a common value of the date variable, I would guess for a report grouping value. The values of vraidate are three, I suppose, different end of&amp;nbsp;period/ year&amp;nbsp;values. Since the loop counters are used in the calculation of DELTAEPS then that appears to be the purpose: calculate 12 delta values for each "date". Why? That is your internal business logic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The repeated use of variable names with components like 12M FY1, FY2 would suggest values associated with fiscal years or similar and may reflect translation of a process originally developed for spreadsheets that might benefit from redesign of the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A large number of follow up processes would not actually need what has been done in that second data set. The only thing I can see is that setting specific variable names may have&amp;nbsp;a step using that data set with those variable names instead of VRAIDATE or DELTAEPS. I might suspect some macro code later that is written with hardcoded variable names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 15:28:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Consecutive-DO-loops-creating-the-same-column-value/m-p/572408#M12317</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-07-10T15:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive DO loops creating the same column value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Consecutive-DO-loops-creating-the-same-column-value/m-p/572410#M12318</link>
      <description>&lt;P&gt;For code conversion, comment every line with what you think is happening, then post it back. We can let you know where you're wrong/right.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Can we assume you understand that SAS goes through data line by line and loops are generally done on a single row of data, because a data step is an automatic loop? I'm also assuming you've ensured your data sets can fit into memory in Python? That's not how SAS processes data - not an in memory application, though CAS is in memory now.&lt;/STRONG&gt; &lt;BR /&gt;&lt;BR /&gt;Unasked for advice: Doing code conversion line by line seems simpler, but actually takes you longer in the long run - from doing many of these projects in various languages. Then take the process and redesign it using the most appropriate python methods, which is likely not looping given how python performs.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 15:30:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Consecutive-DO-loops-creating-the-same-column-value/m-p/572410#M12318</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-10T15:30:16Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive DO loops creating the same column value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Consecutive-DO-loops-creating-the-same-column-value/m-p/572418#M12321</link>
      <description>&lt;P&gt;Thank you so much for this answer! This is helpful.&lt;/P&gt;&lt;P&gt;(yes, my coworker is particularly messy haha)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So what the loops do is group the data by country_name and Secteur, and then create 6&amp;nbsp;&amp;nbsp;(usually delaiFY1 is 6 months) + 12 + 12 respective vraidate and deltaEPS values? (each is indeed for a fiscal year!)&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think the program is supposed to do a linear regression...&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 15:54:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Consecutive-DO-loops-creating-the-same-column-value/m-p/572418#M12321</guid>
      <dc:creator>lalapopia</dc:creator>
      <dc:date>2019-07-10T15:54:42Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive DO loops creating the same column value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Consecutive-DO-loops-creating-the-same-column-value/m-p/572419#M12322</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281086"&gt;@lalapopia&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I don't really follow, isn't delaiFY1 just an integer difference between two dates?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;delaiFY1=intck('month',date,dateFY1);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So the first loop goes from 1 to delaiFY1, say it's 6. Then we create vraidate, but change it in the next loop, which goes from 1 to 12.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What happens to vraidate in the second and third loops?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you run code like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  do fred=1 to 5;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You get a dataset with one variable named FRED and five observations where the value of FRED is different in each of them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your example code is doing the exact same thing, only with a more complicated dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The value of VRAIDATE that SAS currently has in memory is changing as the lines of code in the data step execute.&amp;nbsp; But the OUTPUT statement writes a snapshot of the current values when it executes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The variable VRAIDATE is "created" when SAS compiles the logic of the dataset.&amp;nbsp; So the variable is numeric and has a date format attached to it.&amp;nbsp; Its definition does not change while the step runs just because it is referenced in more than one statement.&amp;nbsp; It is the value of VRAIDATE that will vary.&amp;nbsp; That is why they are called variables.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 15:58:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Consecutive-DO-loops-creating-the-same-column-value/m-p/572419#M12322</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-10T15:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: Consecutive DO loops creating the same column value</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Consecutive-DO-loops-creating-the-same-column-value/m-p/572446#M12324</link>
      <description>&lt;P&gt;Oh, I think I understand now! Thanks a bunch!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Jul 2019 17:40:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Consecutive-DO-loops-creating-the-same-column-value/m-p/572446#M12324</guid>
      <dc:creator>lalapopia</dc:creator>
      <dc:date>2019-07-10T17:40:38Z</dc:date>
    </item>
  </channel>
</rss>

