<?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: How to lag multiple variables by fiscal year end? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-multiple-variables-by-fiscal-year-end/m-p/518789#M140448</link>
    <description>&lt;P&gt;Hello KurtBremser,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That worked! I used %eval instead of %evalf and %to instead of to in the second part.&lt;/P&gt;&lt;P&gt;Thank you so much! One last question, I promise &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; :&lt;/P&gt;&lt;P&gt;What happened to the first few observations for each permno where no prior data is available? How can I set them to missing data (.) ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
    <pubDate>Wed, 05 Dec 2018 14:06:53 GMT</pubDate>
    <dc:creator>salv100</dc:creator>
    <dc:date>2018-12-05T14:06:53Z</dc:date>
    <item>
      <title>How to lag multiple variables by fiscal year end?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-multiple-variables-by-fiscal-year-end/m-p/518730#M140424</link>
      <description>&lt;P&gt;Hey guys!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to lag multiple variables (16 in total, e.g. Earnings, Bookvalue, Dividends,...) &lt;SPAN&gt;for each group (&lt;/SPAN&gt;permno&lt;SPAN&gt;)&amp;nbsp;&lt;/SPAN&gt;depending on their fiscal year-end on SAS 9.4.&lt;/P&gt;&lt;P&gt;Here's what I tried for the variable bookvalue:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let _var=bookvalue;&lt;BR /&gt;Data want;&lt;BR /&gt;SET have;&lt;BR /&gt;by permno;&lt;BR /&gt;If fyr=1 then &amp;amp;_var=lag4(&amp;amp;_var);&lt;BR /&gt;If fyr=2 then &amp;amp;_var=lag5(&amp;amp;_var);&lt;BR /&gt;If fyr=3 then &amp;amp;_var=lag6(&amp;amp;_var);&lt;BR /&gt;If fyr=4 then &amp;amp;_var=lag7(&amp;amp;_var);&lt;BR /&gt;If fyr=5 then &amp;amp;_var=lag8(&amp;amp;_var);&lt;BR /&gt;If fyr=6 then &amp;amp;_var=lag9(&amp;amp;_var);&lt;BR /&gt;If fyr=7 then &amp;amp;_var=lag10(&amp;amp;_var);&lt;BR /&gt;If fyr=8 then &amp;amp;_var=lag11(&amp;amp;_var);&lt;BR /&gt;If fyr=9 then &amp;amp;_var=lag12(&amp;amp;_var);&lt;BR /&gt;If fyr=10 then &amp;amp;_var=lag13(&amp;amp;_var);&lt;BR /&gt;If fyr=11 then &amp;amp;_var=lag14(&amp;amp;_var);&lt;BR /&gt;If fyr=12 then &amp;amp;_var=lag15(&amp;amp;_var);&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It's working fine, but I don't want to repeat that code for each variable. Is there a way to include the other 15 variables?&lt;/P&gt;&lt;P&gt;Thanks a lot!&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, 05 Dec 2018 10:56:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-multiple-variables-by-fiscal-year-end/m-p/518730#M140424</guid>
      <dc:creator>salv100</dc:creator>
      <dc:date>2018-12-05T10:56:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag multiple variables by fiscal year end?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-multiple-variables-by-fiscal-year-end/m-p/518731#M140425</link>
      <description>&lt;P&gt;This is an untested code which could be tried&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let _var=bookvalue;
%macro test;
Data want;
SET have;
by permno;
%do i = 1 %to 12;
If fyr=&amp;amp;i. then &amp;amp;_var=lag%evalf(&amp;amp;i.+3)(&amp;amp;_var);&lt;BR /&gt;%end;
RUN;
%mend;
%test&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Dec 2018 11:01:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-multiple-variables-by-fiscal-year-end/m-p/518731#M140425</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-12-05T11:01:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag multiple variables by fiscal year end?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-multiple-variables-by-fiscal-year-end/m-p/518738#M140430</link>
      <description>&lt;P&gt;Hey Jag,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your fast response! Your code looks great, but doesn't solve my problem. I'd like to lag multiple variables (Bookvalue, Earnings, Dividends,...) at the same time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to include them in the %let statement, but that doesn't work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Wed, 05 Dec 2018 11:18:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-multiple-variables-by-fiscal-year-end/m-p/518738#M140430</guid>
      <dc:creator>salv100</dc:creator>
      <dc:date>2018-12-05T11:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag multiple variables by fiscal year end?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-multiple-variables-by-fiscal-year-end/m-p/518743#M140434</link>
      <description>&lt;P&gt;ok then you can alternatively try to create a dataset with all the variables and use that in this code as below&lt;/P&gt;
&lt;P&gt;so that you could avoid the use of the %let&lt;/P&gt;
&lt;P&gt;This is an untested code, so you need to test and let me know&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data vars;
input vars$10.;
cards;
Bookvalue
Earnings
Dividends
;&lt;BR /&gt;
%macro test;
Data _null_;
set vars;
call execute("data want;SET have;by permno;%do i = 1 %to 12;If fyr=&amp;amp;i. then "||vars||"=lag%evalf(&amp;amp;i.+3)("||strip(vars)||");%end;RUN;");
%mend;
%test&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Dec 2018 11:28:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-multiple-variables-by-fiscal-year-end/m-p/518743#M140434</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-12-05T11:28:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag multiple variables by fiscal year end?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-multiple-variables-by-fiscal-year-end/m-p/518768#M140439</link>
      <description>&lt;P&gt;Try a double macro loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data vars;
input vars$10.;
call symputx(cats('var',_n_),vars);
call symputx('varnum',_n_);
cards;
Bookvalue
Earnings
Dividends
;
run;

%macro test;
data want;
set have;
by permno;
%do j = 1 to &amp;amp;varnum.;
  %do i = 1 %to 12;
  if fyr = &amp;amp;i. then &amp;amp;&amp;amp;var&amp;amp;j. = lag%evalf(&amp;amp;i.+3)(&amp;amp;&amp;amp;var&amp;amp;j.);
  %end;
%end;
run;
%mend;
%test&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Dec 2018 12:45:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-multiple-variables-by-fiscal-year-end/m-p/518768#M140439</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-12-05T12:45:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag multiple variables by fiscal year end?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-multiple-variables-by-fiscal-year-end/m-p/518789#M140448</link>
      <description>&lt;P&gt;Hello KurtBremser,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That worked! I used %eval instead of %evalf and %to instead of to in the second part.&lt;/P&gt;&lt;P&gt;Thank you so much! One last question, I promise &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; :&lt;/P&gt;&lt;P&gt;What happened to the first few observations for each permno where no prior data is available? How can I set them to missing data (.) ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&lt;/P&gt;</description>
      <pubDate>Wed, 05 Dec 2018 14:06:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-multiple-variables-by-fiscal-year-end/m-p/518789#M140448</guid>
      <dc:creator>salv100</dc:creator>
      <dc:date>2018-12-05T14:06:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to lag multiple variables by fiscal year end?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-lag-multiple-variables-by-fiscal-year-end/m-p/518799#M140452</link>
      <description>&lt;P&gt;Add a counter that starts with every permno:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro test;
data want;
set have;
by permno;
if first.permno
then count = 1;
else count + 1;
%do j = 1 to &amp;amp;varnum.;
  %do i = 1 %to 12;
  if fyr = &amp;amp;i. and count &amp;gt;= &amp;amp;i. + 4 then &amp;amp;&amp;amp;var&amp;amp;j. = lag%evalf(&amp;amp;i.+3)(&amp;amp;&amp;amp;var&amp;amp;j.);
  %end;
%end;
run;
%mend;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 05 Dec 2018 14:20:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-lag-multiple-variables-by-fiscal-year-end/m-p/518799#M140452</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-12-05T14:20:26Z</dc:date>
    </item>
  </channel>
</rss>

