<?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: if then statement in the proc expand ? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-in-the-proc-expand/m-p/434105#M68859</link>
    <description>&lt;P&gt;BTW what are you trying to do with&lt;/P&gt;
&lt;PRE&gt;max_gdp_hist&amp;amp;j&lt;/PRE&gt;
&lt;P&gt;I see no variable beginning with max_gdp_hist in your dataset. Are you trying to do an indirect reference on macro variables called max_gdp_hist3, max_gdp_hist6, max_gdp_hist9, max_gdp_hist12? If yes, where are they created?&lt;/P&gt;
&lt;P&gt;And you go to great lengths creating the macro variable &amp;amp;k and then never use it. You only repeat identical code 4 times because of the&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do k_index=1 %to 4;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;loop.&lt;/P&gt;</description>
    <pubDate>Mon, 05 Feb 2018 09:29:42 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-02-05T09:29:42Z</dc:date>
    <item>
      <title>if then statement in the proc expand ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-in-the-proc-expand/m-p/434062#M68849</link>
      <description>&lt;P&gt;Could I use if-then statement in the proc expand as follows?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro all16;&lt;/P&gt;&lt;P&gt;%local j_list k_list j k j_index k_index;&lt;/P&gt;&lt;P&gt;%let j_list = 3 6 9 12;&lt;/P&gt;&lt;P&gt;%let k_list =3 3 3 3;&lt;/P&gt;&lt;P&gt;%do j_index=1 %to 4;&lt;/P&gt;&lt;P&gt;%let j = %scan(&amp;amp;j_list, &amp;amp;j_index);&lt;/P&gt;&lt;P&gt;%do k_index=1 %to 4;&lt;/P&gt;&lt;P&gt;%let k = %scan(&amp;amp;k_list, &amp;amp;k_index);&lt;/P&gt;&lt;P&gt;data vickyhave;&lt;BR /&gt;input date :yymmdd10. gdp country;&lt;BR /&gt;format date yymmdds10.;&lt;BR /&gt;cards;&lt;BR /&gt;19800131 28 222&lt;BR /&gt;19800229 29.375 222&lt;BR /&gt;19800331 27.125 222&lt;BR /&gt;19800430 24.25 222&lt;BR /&gt;19800530 26.75 222&lt;BR /&gt;19800630 30.75 222&lt;BR /&gt;19800731 37.75 222&lt;BR /&gt;19800829 40.75 222&lt;BR /&gt;19800930 43.375 222&lt;BR /&gt;19801031 51.5 222&lt;BR /&gt;19801128 56 222&lt;BR /&gt;19801231 24.5 222&lt;BR /&gt;19810130 22.25 222&lt;BR /&gt;19810227 20 222&lt;BR /&gt;19810331 22.75 222&lt;BR /&gt;19810430 20.5 222&lt;BR /&gt;19810529 19.5 222&lt;BR /&gt;19810630 18 222&lt;BR /&gt;19810731 18.5 222&lt;BR /&gt;19810831 17.5 222&lt;BR /&gt;19810930 14.25 222&lt;BR /&gt;19811030 14.375 222&lt;BR /&gt;19811130 15.75 222&lt;BR /&gt;19811231 14.625 222&lt;BR /&gt;19820129 14.625 222&lt;BR /&gt;19820226 12.875 222&lt;BR /&gt;19820331 12.625 222&lt;BR /&gt;19820430 12.625 222&lt;BR /&gt;19820528 12 222&lt;BR /&gt;19820630 12.125 222&lt;BR /&gt;19820730 10.875 222&lt;BR /&gt;19820831 11.375 222&lt;BR /&gt;19820930 11.75 222&lt;BR /&gt;19821029 14.25 222&lt;BR /&gt;19821130 13.75 222&lt;BR /&gt;19821231 13 222&lt;BR /&gt;19830131 14.25 222&lt;BR /&gt;19830228 13.5 222&lt;BR /&gt;19830331 14 222&lt;BR /&gt;19830429 14.625 222&lt;BR /&gt;19830531 14.5 222&lt;BR /&gt;19830630 15.75 222&lt;BR /&gt;19830729 15.375 222&lt;BR /&gt;19830831 14.625 222&lt;BR /&gt;19830930 16.625 222&lt;BR /&gt;19831031 15 222&lt;BR /&gt;19831130 15 222&lt;BR /&gt;19831230 15.5 222&lt;BR /&gt;19840131 15.375 222&lt;BR /&gt;19840229 14 222&lt;BR /&gt;19840330 13.625 222&lt;BR /&gt;19840430 12.125 222&lt;BR /&gt;19840531 11.625 222&lt;BR /&gt;19840629 11.5 222&lt;BR /&gt;19840731 10.125 222&lt;BR /&gt;19840831 11.875 222&lt;BR /&gt;19840928 12.125 222&lt;BR /&gt;19841031 12.25 222&lt;BR /&gt;19841130 11.5 222&lt;BR /&gt;19841231 11.125 222&lt;BR /&gt;19850131 13.5 222&lt;BR /&gt;19850228 14.875 222&lt;BR /&gt;19850329 14.25 222&lt;BR /&gt;19850430 13.625 222&lt;BR /&gt;19850531 13.25 222&lt;BR /&gt;19850628 13.375 222&lt;BR /&gt;19850731 13.75 222&lt;BR /&gt;19850830 12.75 222&lt;BR /&gt;19850930 12.25 222&lt;BR /&gt;19851031 11.25 222&lt;BR /&gt;19851129 12 222&lt;BR /&gt;19851231 12.75 222&lt;BR /&gt;19860131 13.125 222&lt;BR /&gt;19860228 14 222&lt;BR /&gt;19860331 14.5 222&lt;BR /&gt;19860430 13.25 222&lt;BR /&gt;19860530 13.875 222&lt;BR /&gt;19860630 13.5 222&lt;BR /&gt;19860731 11.875 222&lt;BR /&gt;19860829 12.25 222&lt;BR /&gt;19860930 11.25 222&lt;BR /&gt;19861031 13.25 222&lt;BR /&gt;19861128 13 222&lt;BR /&gt;19861231 13.125 222&lt;BR /&gt;19870130 17 222&lt;BR /&gt;19870227 17 222&lt;BR /&gt;19870331 16 222&lt;BR /&gt;19870430 15.25 222&lt;BR /&gt;19870529 19.5 222&lt;BR /&gt;19870630 20.25 222&lt;BR /&gt;19870731 22 222&lt;BR /&gt;19870831 22 222&lt;BR /&gt;19870930 21.625 222&lt;BR /&gt;19871030 13.125 222&lt;BR /&gt;19871130 10.875 222&lt;BR /&gt;19871231 13.75 222&lt;BR /&gt;19880129 14.5 222&lt;BR /&gt;19880229 14.75 222&lt;BR /&gt;19880331 13.125 222&lt;BR /&gt;19880429 12 222&lt;BR /&gt;19880531 13.375 222&lt;BR /&gt;19880630 16.625 222&lt;BR /&gt;19880729 15.5 222&lt;BR /&gt;19880831 15.875 222&lt;BR /&gt;19880930 15.25 222&lt;BR /&gt;19881031 14.375 222&lt;BR /&gt;19881130 13.375 222&lt;BR /&gt;19881230 14.5 222&lt;BR /&gt;19890131 16.125 222&lt;BR /&gt;19890228 16.625 222&lt;BR /&gt;19890331 17 222&lt;BR /&gt;19890428 18.25 222&lt;BR /&gt;19890531 20 222&lt;BR /&gt;19890630 18.625 222&lt;BR /&gt;19890731 21 222&lt;BR /&gt;19890831 21.25 222&lt;BR /&gt;19890929 20 222&lt;BR /&gt;19891031 17.375 222&lt;BR /&gt;19891130 19.875 222&lt;BR /&gt;19891229 20.75 222&lt;BR /&gt;19800131 25.75 257&lt;BR /&gt;19800229 25.625 257&lt;BR /&gt;19800331 20.375 257&lt;BR /&gt;19800430 20.5 257&lt;BR /&gt;19800530 20.75 257&lt;BR /&gt;19800630 22 257&lt;BR /&gt;19800731 21.625 257&lt;BR /&gt;19800829 22.875 257&lt;BR /&gt;19800930 24.375 257&lt;BR /&gt;19801031 24.5 257&lt;BR /&gt;19801128 24.5 257&lt;BR /&gt;19801231 22.875 257&lt;BR /&gt;19810130 23.75 257&lt;BR /&gt;19810227 24.875 257&lt;BR /&gt;19810331 28.5 257&lt;BR /&gt;19810430 27.75 257&lt;BR /&gt;19810529 27.5 257&lt;BR /&gt;19810630 27.125 257&lt;BR /&gt;19810731 29.5 257&lt;BR /&gt;19810831 26.875 257&lt;BR /&gt;19810930 27.5 257&lt;BR /&gt;19811030 26.75 257&lt;BR /&gt;19811130 25.75 257&lt;BR /&gt;19811231 23.25 257&lt;BR /&gt;19820129 23.5 257&lt;BR /&gt;19820226 22.375 257&lt;BR /&gt;19820331 22.625 257&lt;BR /&gt;19820430 22.125 257&lt;BR /&gt;19820528 23.125 257&lt;BR /&gt;19820630 22.75 257&lt;BR /&gt;19820730 20.5 257&lt;BR /&gt;19820831 23.5 257&lt;BR /&gt;19820930 24.25 257&lt;BR /&gt;19821029 27.75 257&lt;BR /&gt;19821130 31 257&lt;BR /&gt;19821231 30 257&lt;BR /&gt;19830131 31.25 257&lt;BR /&gt;19830228 30.875 257&lt;BR /&gt;19830331 33.75 257&lt;BR /&gt;19830429 32.875 257&lt;BR /&gt;19830531 34.375 257&lt;BR /&gt;19830630 36.25 257&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;proc expand data= vickyhave&lt;BR /&gt;out=vickywant (where=((gdp&amp;gt;=max_gdp_hist&amp;amp;j) and (centered_window_range=2*&amp;amp;J+1)))&lt;BR /&gt;method=none ;&lt;BR /&gt;by country;&lt;BR /&gt;id date;&lt;BR /&gt;convert gdp=max_gdp_hist&amp;amp;j / transformin=(lag 1) transformout=(nomiss movmax &amp;amp;j);&lt;BR /&gt;convert gdp=centered_window_range / transformin=(*0 +1 cmovsum 2*&amp;amp;J+1 ) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if j=3 then convert gdp=gmean_future_rate_3 / transformin=(ratio 1 log cmovave ( 0 0 0 0 1 1 0) exp -1);&lt;/P&gt;&lt;P&gt;else if j=6 then convert gdp=gmean_future_rate_3 / transformin=(ratio 1 log cmovave ( 0 0 0 0 0 0 0 1 1 0) exp -1);&lt;/P&gt;&lt;P&gt;else if j=9 then convert gdp=gmean_future_rate_3 / transformin=(ratio 1 log cmovave ( 0 0 0 0 0 0 0 0 0 0 1 1 0) exp -1);&lt;/P&gt;&lt;P&gt;else convert gdp=gmean_future_rate_3 / transformin=(ratio 1 log cmovave ( 0 0 0 0 0 0 0 0 0 0 1 1 0) exp -1);&lt;BR /&gt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%mend all16;&lt;BR /&gt;%all16;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 06:51:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-in-the-proc-expand/m-p/434062#M68849</guid>
      <dc:creator>vickyCh</dc:creator>
      <dc:date>2018-02-05T06:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: if then statement in the proc expand ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-in-the-proc-expand/m-p/434099#M68854</link>
      <description>&lt;P&gt;Maxim 1: read the documentation: &lt;A href="http://support.sas.com/documentation/cdl/en/etsug/60372/HTML/default/viewer.htm#etsug_expand_sect013.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/etsug/60372/HTML/default/viewer.htm#etsug_expand_sect013.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The EXPAND procedure supports a BY, CONVERT and ID statement, that's it.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 09:14:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-in-the-proc-expand/m-p/434099#M68854</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-02-05T09:14:43Z</dc:date>
    </item>
    <item>
      <title>Re: if then statement in the proc expand ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-in-the-proc-expand/m-p/434101#M68856</link>
      <description>&lt;P&gt;But it looks to me you want your macro to generate dynamic code, so the proc expand would look like that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc expand
  data= vickyhave
  out=vickywant (
    where=((gdp&amp;gt;=max_gdp_hist&amp;amp;j) and (centered_window_range=2*&amp;amp;J+1))
  )
  method=none 
;
by country;
id date;
convert gdp=max_gdp_hist&amp;amp;j / transformin=(lag 1) transformout=(nomiss movmax &amp;amp;j);
convert gdp=centered_window_range / transformin=(*0 +1 cmovsum 2*&amp;amp;J+1 );
%if &amp;amp;j=3 %then %do;
convert gdp=gmean_future_rate_3 / transformin=(ratio 1 log cmovave ( 0 0 0 0 1 1 0) exp -1);
%end;
%else %if &amp;amp;j=6 %then %do;
convert gdp=gmean_future_rate_3 / transformin=(ratio 1 log cmovave ( 0 0 0 0 0 0 0 1 1 0) exp -1);
%end;
%else %if &amp;amp;j=9 %then %do;
convert gdp=gmean_future_rate_3 / transformin=(ratio 1 log cmovave ( 0 0 0 0 0 0 0 0 0 0 1 1 0) exp -1);
%end;
%else %do;
convert gdp=gmean_future_rate_3 / transformin=(ratio 1 log cmovave ( 0 0 0 0 0 0 0 0 0 0 1 1 0) exp -1);
%end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since the only thing that changes is the parameter string in the brackets, you could create that with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
length parmstr $50;
do i = 1 to &amp;amp;j;
  parmstr = catx(' ',parmstr,put(i,best.));
end;
parmstr = trim(parmstr) !! ' 0 1 1 0';
call symput('parmstr',trim(parmstr));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and so avoid the %if by having a single convert statement with &amp;amp;parmstr.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 09:23:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-in-the-proc-expand/m-p/434101#M68856</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-02-05T09:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: if then statement in the proc expand ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-in-the-proc-expand/m-p/434105#M68859</link>
      <description>&lt;P&gt;BTW what are you trying to do with&lt;/P&gt;
&lt;PRE&gt;max_gdp_hist&amp;amp;j&lt;/PRE&gt;
&lt;P&gt;I see no variable beginning with max_gdp_hist in your dataset. Are you trying to do an indirect reference on macro variables called max_gdp_hist3, max_gdp_hist6, max_gdp_hist9, max_gdp_hist12? If yes, where are they created?&lt;/P&gt;
&lt;P&gt;And you go to great lengths creating the macro variable &amp;amp;k and then never use it. You only repeat identical code 4 times because of the&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do k_index=1 %to 4;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;loop.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 09:29:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-in-the-proc-expand/m-p/434105#M68859</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-02-05T09:29:42Z</dc:date>
    </item>
    <item>
      <title>Re: if then statement in the proc expand ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-in-the-proc-expand/m-p/434466#M68894</link>
      <description>&lt;P&gt;I am grateful for your support, KurtBremser.&lt;BR /&gt;Allow me to clarify some points you mentioned. The max_gdp_hist was to fulfill the needs of the research that “In the time series of gdp for several countries (part of the data is attached), we want to know the continuing performance of gdp of each country.”&lt;BR /&gt;1) We want to identify the date (maybe many observations would satisfy the requirement in the series) that was better than the maximum gdp value of the past 6 months and its future growth rate.&lt;BR /&gt;2) The posted coding was only part of the whole coding and &amp;amp;k would appear in somewhere at the other part of the coding.&lt;BR /&gt;3) The macro coding you posted is good enough for me. However, I wonder what would happen to “call symput” if the “if-then condition” is like the following instead of the previous one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%if &amp;amp;j=3 %then %do;&lt;BR /&gt;convert prc=gmean_future_rate_3 / transformin=(ratio 1 log cmovave ( 0 0 0 0 1 1 0) exp -1);&lt;BR /&gt;%end;&lt;BR /&gt;%else %if &amp;amp;j=6 %then %do;&lt;BR /&gt;convert prc=gmean_future_rate_3 / transformin=(ratio 1 log cmovave ( 0 0 0 0 0 0 0 1 1 0 0 0 0) exp -1);&lt;BR /&gt;%end;&lt;BR /&gt;%else %if &amp;amp;j=9 %then %do;&lt;BR /&gt;convert prc=gmean_future_rate_3 / transformin=(ratio 1 log cmovave ( 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0) exp -1);&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;convert prc=gmean_future_rate_3 / transformin=(ratio 1 log cmovave ( 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 ) exp -1);&lt;BR /&gt;%end;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 06:38:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-in-the-proc-expand/m-p/434466#M68894</guid>
      <dc:creator>vickyCh</dc:creator>
      <dc:date>2018-02-06T06:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: if then statement in the proc expand ?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-in-the-proc-expand/m-p/434468#M68895</link>
      <description>&lt;P&gt;Well, you need to implemet your rule in the data step code that builds the string. The call symput just sets the macro variable to the contents of the string.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 06:45:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/if-then-statement-in-the-proc-expand/m-p/434468#M68895</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-02-06T06:45:33Z</dc:date>
    </item>
  </channel>
</rss>

