<?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: Macro or Array in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-or-Array/m-p/687441#M208689</link>
    <description>&lt;P&gt;I don't see why you would need a macro. But an array can do it like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data wanted;
set have2;
by ID;
array y (5) y1-y5;
IF not first.ID then do;
	do i=1 to 5;
		y(i)=.;
	end;
end;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 29 Sep 2020 08:48:13 GMT</pubDate>
    <dc:creator>rudfaden</dc:creator>
    <dc:date>2020-09-29T08:48:13Z</dc:date>
    <item>
      <title>Macro or Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-or-Array/m-p/687440#M208688</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want that for each ID:&lt;/P&gt;
&lt;P&gt;in first raw values of Y1-Y5 will be non-null .&lt;/P&gt;
&lt;P&gt;in non-first raw values of Y1-Y5 will be-null .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In real data there are 100 Y variables (Y1,Y2,........Y100).&lt;/P&gt;
&lt;P&gt;What is the way to write the following statements in macro or array?&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;IF not first.ID then do;
Y1=.;
Y2=.;
Y3=.;
Y4=.;
Y5=.;
end;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input ID X $ Y1 Y2 Y3 Y4 Y5;
cards;
3 B 5 3 1 2 1
3 C 1 4 2 3 1 
1 A 1 2 3 4 5 
1 B 2 3 2 4 1 
1 C 3 1 2 1 2
2 A 1 3 2 4 5
2 C 2 5 4 3 2 
4 B 1 3 2 1 4
;
run;

proc sort data=have out=have2;
by ID;
Run;


data wanted;
set have2;
by ID;
IF not first.ID then do;
Y1=.;
Y2=.;
Y3=.;
Y4=.;
Y5=.;
end;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 08:37:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-or-Array/m-p/687440#M208688</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-09-29T08:37:21Z</dc:date>
    </item>
    <item>
      <title>Re: Macro or Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-or-Array/m-p/687441#M208689</link>
      <description>&lt;P&gt;I don't see why you would need a macro. But an array can do it like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data wanted;
set have2;
by ID;
array y (5) y1-y5;
IF not first.ID then do;
	do i=1 to 5;
		y(i)=.;
	end;
end;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 08:48:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-or-Array/m-p/687441#M208689</guid>
      <dc:creator>rudfaden</dc:creator>
      <dc:date>2020-09-29T08:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: Macro or Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-or-Array/m-p/687451#M208695</link>
      <description>&lt;P&gt;If all your variables to be set start with the same prefix, you can suimplify&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/117666"&gt;@rudfaden&lt;/a&gt;&amp;nbsp;'s suggestion:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data wanted;
set have2;
by ID;
array my_y (*) y:;
if not first.ID then do i = 1 to dim(my_y);
  my_y(i) = .;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 09:07:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-or-Array/m-p/687451#M208695</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-29T09:07:53Z</dc:date>
    </item>
    <item>
      <title>Re: Macro or Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-or-Array/m-p/687452#M208696</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another solution without array :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data wanted;
set have2;
by ID;
if not first.id then call missing(of y:);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 09:20:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-or-Array/m-p/687452#M208696</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2020-09-29T09:20:26Z</dc:date>
    </item>
    <item>
      <title>Re: Macro or Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-or-Array/m-p/687458#M208698</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF not first.ID then call missing(of y1-y5);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;No loops at all.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 10:47:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-or-Array/m-p/687458#M208698</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-29T10:47:21Z</dc:date>
    </item>
    <item>
      <title>Re: Macro or Array</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-or-Array/m-p/688440#M209130</link>
      <description>&lt;P&gt;Very nice. I like this version better than mine &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Oct 2020 07:41:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-or-Array/m-p/688440#M209130</guid>
      <dc:creator>rudfaden</dc:creator>
      <dc:date>2020-10-02T07:41:27Z</dc:date>
    </item>
  </channel>
</rss>

