<?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: loop column names using macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/loop-column-names-using-macro/m-p/454581#M114893</link>
    <description>&lt;P&gt;Sorry, must have misread your question. You have everything you need to do this and you don't need macros.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the variables were listed side by side you could also use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array PATCH(*) FirstVarName -- LastVarName;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work;

set have;
array Patch (*) &amp;amp;varList.;

do i = 1 to dim(Patch) ;
    if not missing(patch(i)) then patch(i) = APP_ID;
end;


run;

 &lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 16 Apr 2018 21:30:07 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-04-16T21:30:07Z</dc:date>
    <item>
      <title>loop column names using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/loop-column-names-using-macro/m-p/454575#M114891</link>
      <description>&lt;P&gt;i have column names like&amp;nbsp; below, if data missing in that column insert null else insert App_id&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc contents data=patch.Windows_patch out=patch.contents noprint; run;&lt;BR /&gt;&lt;BR /&gt;proc sql ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; select name into :varlist separated by ' '&lt;BR /&gt;&amp;nbsp; from patch.contents where name like '%CHG%';&lt;BR /&gt;%let n=&amp;amp;obs;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;do i = 1 to &amp;amp;n ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if &amp;amp;Patch {i} =' ' then&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;amp;patch{i}=' '&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;else&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;amp;patch{i}=App_ID;&lt;BR /&gt;end;&lt;BR /&gt;run;&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Apr 2018 20:57:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/loop-column-names-using-macro/m-p/454575#M114891</guid>
      <dc:creator>radha009</dc:creator>
      <dc:date>2018-04-16T20:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: loop column names using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/loop-column-names-using-macro/m-p/454577#M114892</link>
      <description>&lt;P&gt;Use a data step and an array instead. SQL doesn't lend itself well to variable lists and multiple variables well and then you can avoid using a macro entirely.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/192083"&gt;@radha009&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;i have column names like&amp;nbsp; below, if data missing in that column insert null else insert App_id&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc contents data=patch.Windows_patch out=patch.contents noprint; run;&lt;BR /&gt;&lt;BR /&gt;proc sql ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; select name into :varlist separated by ' '&lt;BR /&gt;&amp;nbsp; from patch.contents where name like '%CHG%';&lt;BR /&gt;%let n=&amp;amp;obs;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data work;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;do i = 1 to &amp;amp;n ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;if &amp;amp;Patch {i} =' ' then&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;amp;patch{i}=' '&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;else&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;amp;patch{i}=App_ID;&lt;BR /&gt;end;&lt;BR /&gt;run;&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;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Apr 2018 21:00:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/loop-column-names-using-macro/m-p/454577#M114892</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-16T21:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: loop column names using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/loop-column-names-using-macro/m-p/454581#M114893</link>
      <description>&lt;P&gt;Sorry, must have misread your question. You have everything you need to do this and you don't need macros.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the variables were listed side by side you could also use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;array PATCH(*) FirstVarName -- LastVarName;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work;

set have;
array Patch (*) &amp;amp;varList.;

do i = 1 to dim(Patch) ;
    if not missing(patch(i)) then patch(i) = APP_ID;
end;


run;

 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Apr 2018 21:30:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/loop-column-names-using-macro/m-p/454581#M114893</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-04-16T21:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: loop column names using macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/loop-column-names-using-macro/m-p/454625#M114901</link>
      <description>&lt;P&gt;And make the creation of varlist simpler:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint ;
select name into :varlist separated by ' '
from dictionary.columns
where
  libname = "PATCH" and
  memname = "WINDOWS_PATCH" and
  name like '%CHG%';
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;No proc contents needed.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Apr 2018 04:58:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/loop-column-names-using-macro/m-p/454625#M114901</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-17T04:58:19Z</dc:date>
    </item>
  </channel>
</rss>

