<?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 if else macro loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/if-else-macro-loop/m-p/243004#M45151</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have longitudnal data and grp variable and fl variable, values of grp as 1 2 3 4 5 6... and values for fl as 1 2 3... need to create variable net.&lt;/P&gt;
&lt;P&gt;Is there any dynamic way to get the grp and fl values&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if grp=1 then do; if fl=1 then net=1; if fl=2 then net=2;end;&lt;BR /&gt;if grp=2 then do; if fl=1 then net=3; if fl=2 then net=4;end;&lt;BR /&gt;if grp=3 then do; if fl=1 then net=5; if fl=2 then net=6;end;&lt;BR /&gt;if grp=4 then do; if fl=1 then net=7; if fl=2 then net=8;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;my try :&lt;/P&gt;
&lt;P&gt;%let maxgrp=4;%let fl=2;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;select *,&lt;/P&gt;
&lt;P&gt;%do i=1 %to &amp;amp;maxgrp;&amp;nbsp; j=1 %to &amp;amp;fl;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case when grp=&amp;amp;i and fl eq &amp;amp;j then &amp;amp;i*&amp;amp;j;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end as trt&lt;/P&gt;
&lt;P&gt;from ids;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Sam&lt;/P&gt;</description>
    <pubDate>Tue, 12 Jan 2016 18:30:58 GMT</pubDate>
    <dc:creator>sam369</dc:creator>
    <dc:date>2016-01-12T18:30:58Z</dc:date>
    <item>
      <title>if else macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-else-macro-loop/m-p/243004#M45151</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have longitudnal data and grp variable and fl variable, values of grp as 1 2 3 4 5 6... and values for fl as 1 2 3... need to create variable net.&lt;/P&gt;
&lt;P&gt;Is there any dynamic way to get the grp and fl values&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if grp=1 then do; if fl=1 then net=1; if fl=2 then net=2;end;&lt;BR /&gt;if grp=2 then do; if fl=1 then net=3; if fl=2 then net=4;end;&lt;BR /&gt;if grp=3 then do; if fl=1 then net=5; if fl=2 then net=6;end;&lt;BR /&gt;if grp=4 then do; if fl=1 then net=7; if fl=2 then net=8;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;my try :&lt;/P&gt;
&lt;P&gt;%let maxgrp=4;%let fl=2;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;select *,&lt;/P&gt;
&lt;P&gt;%do i=1 %to &amp;amp;maxgrp;&amp;nbsp; j=1 %to &amp;amp;fl;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case when grp=&amp;amp;i and fl eq &amp;amp;j then &amp;amp;i*&amp;amp;j;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end as trt&lt;/P&gt;
&lt;P&gt;from ids;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;Sam&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jan 2016 18:30:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-else-macro-loop/m-p/243004#M45151</guid>
      <dc:creator>sam369</dc:creator>
      <dc:date>2016-01-12T18:30:58Z</dc:date>
    </item>
    <item>
      <title>Re: if else macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-else-macro-loop/m-p/243007#M45154</link>
      <description>You can simplify it to a formula:&lt;BR /&gt;&lt;BR /&gt;net=(2*(grp-1))+fl;</description>
      <pubDate>Tue, 12 Jan 2016 18:33:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-else-macro-loop/m-p/243007#M45154</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-01-12T18:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: if else macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-else-macro-loop/m-p/243025#M45163</link>
      <description>&lt;P&gt;Thank you Reeza!!!&lt;/P&gt;
&lt;P&gt;can we adopt this formula under the sql? if i used in data step i got the output , but if i want to adopt for sql, getting warning on log,&lt;/P&gt;
&lt;P&gt;"net variable already exit in XXXX dataset"&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;Thanks&lt;/P&gt;
&lt;P&gt;Sam&lt;/P&gt;</description>
      <pubDate>Tue, 12 Jan 2016 19:13:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-else-macro-loop/m-p/243025#M45163</guid>
      <dc:creator>sam369</dc:creator>
      <dc:date>2016-01-12T19:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: if else macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-else-macro-loop/m-p/243047#M45178</link>
      <description>In SQL it would work as well but it would be&lt;BR /&gt;(2*(grp-1))+fl as net&lt;BR /&gt;&lt;BR /&gt;If the NET variable already exists in the dataset, as your warning indicates that something to be cautious of, do you really want to overwrite the other variable called net.  In a data step it would overwrite it without any warning.</description>
      <pubDate>Tue, 12 Jan 2016 20:33:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-else-macro-loop/m-p/243047#M45178</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-01-12T20:33:39Z</dc:date>
    </item>
  </channel>
</rss>

