<?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: Multiply alternately by 2 and 1 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiply-alternately-by-2-and-1/m-p/831891#M328793</link>
    <description>&lt;P&gt;Use the Mod Function in %Sysfunc. See if you can use this as a template.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro m;
   %do i = 1 %to 10;
      %if %sysfunc(mod(&amp;amp;i, 2)) = 0 %then %put &amp;amp;i. is even!;
      %else %put &amp;amp;i. is odd!;
   %end;
%mend;

%m&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 06 Sep 2022 09:21:15 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2022-09-06T09:21:15Z</dc:date>
    <item>
      <title>Multiply alternately by 2 and 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiply-alternately-by-2-and-1/m-p/831890#M328792</link>
      <description>&lt;P&gt;Does anyone have a nice solution on how to multiply every first position with 2 and every second position with 1?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please see example below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Check;
data Check;
	set sashelp.Margarin (keep= HouseID);
	HouseIDtxt=put(HouseId,7.0);
	%do i= 1 %to 7;
	HousIDPosition&amp;amp;i=substr(HouseIDtxt,&amp;amp;i,1);
	%end;
run;
%mend Check;
%Check&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Every time &lt;CODE class=" language-sas"&gt;&amp;amp;i&lt;/CODE&gt; is odd I want&amp;nbsp;&lt;CODE class=" language-sas"&gt;HousIDPosition&amp;amp;i&lt;/CODE&gt;&amp;nbsp;to&amp;nbsp;be multiplied by 2 and every time &lt;CODE class=" language-sas"&gt;&amp;amp;i&lt;/CODE&gt; is even I want it multiplied by 1.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2022 09:17:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiply-alternately-by-2-and-1/m-p/831890#M328792</guid>
      <dc:creator>Multipla99</dc:creator>
      <dc:date>2022-09-06T09:17:10Z</dc:date>
    </item>
    <item>
      <title>Re: Multiply alternately by 2 and 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiply-alternately-by-2-and-1/m-p/831891#M328793</link>
      <description>&lt;P&gt;Use the Mod Function in %Sysfunc. See if you can use this as a template.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro m;
   %do i = 1 %to 10;
      %if %sysfunc(mod(&amp;amp;i, 2)) = 0 %then %put &amp;amp;i. is even!;
      %else %put &amp;amp;i. is odd!;
   %end;
%mend;

%m&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Sep 2022 09:21:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiply-alternately-by-2-and-1/m-p/831891#M328793</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-09-06T09:21:15Z</dc:date>
    </item>
    <item>
      <title>Re: Multiply alternately by 2 and 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiply-alternately-by-2-and-1/m-p/831909#M328808</link>
      <description>&lt;P&gt;Btw, here is my final code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro Check;
data Check;
	set sashelp.Margarin (keep= HouseID);
	HouseIDtxt=put(HouseId,7.0);
	%do i= 1 %to 7;
	 %if %sysfunc(mod(&amp;amp;i, 2)) = 0 %then %do;
	  HousIDPositionMult&amp;amp;i= substr(HouseIDtxt,&amp;amp;i,1)*1;
	 %end;
	 %else %do;
	  HousIDPositionMult&amp;amp;i= substr(HouseIDtxt,&amp;amp;i,1)*2;
	 %end;
	%end;
run;
%mend Check;
%Check
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Sep 2022 12:17:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiply-alternately-by-2-and-1/m-p/831909#M328808</guid>
      <dc:creator>Multipla99</dc:creator>
      <dc:date>2022-09-06T12:17:20Z</dc:date>
    </item>
    <item>
      <title>Re: Multiply alternately by 2 and 1</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiply-alternately-by-2-and-1/m-p/831920#M328813</link>
      <description>&lt;P&gt;Instead of a macro you could use an array in the data step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data check(drop=i);
set sashelp.Margarin(keep=HouseID);
array HousIDPositionMult[7];
do i=1 to 7;
  HousIDPositionMult[i]=mod(int(HouseID/10**(7-i)),10)*(mod(i,2)+1);
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This would also avoid the unwanted notes "&lt;FONT face="courier new,courier"&gt;Character values have been converted to numeric values&lt;/FONT&gt; ..." in the log as it multiplies numbers, not character strings.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Sep 2022 12:56:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiply-alternately-by-2-and-1/m-p/831920#M328813</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-09-06T12:56:57Z</dc:date>
    </item>
  </channel>
</rss>

