<?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: how to write a loop macro to proc contents for a set of datasets in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/how-to-write-a-loop-macro-to-proc-contents-for-a-set-of-datasets/m-p/833620#M35786</link>
    <description>&lt;P&gt;1) What do you mean by 'Doesn't work''&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Where does the list of data set names come from? Are they in a data set? If so, there are better ways.&lt;/P&gt;</description>
    <pubDate>Thu, 15 Sep 2022 14:59:22 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2022-09-15T14:59:22Z</dc:date>
    <item>
      <title>how to write a loop macro to proc contents for a set of datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-write-a-loop-macro-to-proc-contents-for-a-set-of-datasets/m-p/833617#M35785</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;i have about 30 datasets that i need to write a macro to get the proc contents from each dataset. i am new to the macro. i write the following but it doesn't work. can any expert take a look at my code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro C1 (ennloop, list);&lt;BR /&gt;%do i = 1 %to &amp;amp;endloop.; &lt;BR /&gt;%let dem = %scan(&amp;amp;list., &amp;amp;i.);&lt;BR /&gt;proc contents data=&amp;amp;list;&lt;BR /&gt;run;&lt;BR /&gt;end;&lt;BR /&gt;%mend;&lt;BR /&gt;%C1(2, c2010 c2016 d2016 d2017 f2016 f2019);&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 14:55:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-write-a-loop-macro-to-proc-contents-for-a-set-of-datasets/m-p/833617#M35785</guid>
      <dc:creator>juliajulia</dc:creator>
      <dc:date>2022-09-15T14:55:58Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a loop macro to proc contents for a set of datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-write-a-loop-macro-to-proc-contents-for-a-set-of-datasets/m-p/833620#M35786</link>
      <description>&lt;P&gt;1) What do you mean by 'Doesn't work''&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) Where does the list of data set names come from? Are they in a data set? If so, there are better ways.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 14:59:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-write-a-loop-macro-to-proc-contents-for-a-set-of-datasets/m-p/833620#M35786</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-09-15T14:59:22Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a loop macro to proc contents for a set of datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-write-a-loop-macro-to-proc-contents-for-a-set-of-datasets/m-p/833653#M35787</link>
      <description>&lt;P&gt;Might be easier to get all the data sets in the library&lt;/P&gt;
&lt;P&gt;Proc contents data=work._all_;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;would provide contents for all the data sets in the Work library.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note in your code:&lt;/P&gt;
&lt;PRE&gt;%macro C1 (ennloop, list);
%do i = 1 %to &amp;amp;endloop.;
%let dem = %scan(&amp;amp;list., &amp;amp;i.);
proc contents data=&amp;amp;list;
run;
end;
%mend;&lt;/PRE&gt;
&lt;P&gt;You do not have an "endloop" parameter. Your macro statement defines "ennloop".&amp;nbsp; Which should show one or more notes in the LOG (you do read the LOG don't your?)&lt;/P&gt;
&lt;P&gt;No need to even pass such a count. You can use&amp;nbsp; %do i = %sysfunc(countw(&amp;amp;list.)); and let the program count the number of values you pass in LIST so you don't have to.&lt;/P&gt;
&lt;P&gt;NOTE that you example call to the macro&lt;/P&gt;
&lt;PRE&gt;%C1(2, c2010 c2016 d2016 d2017 f2016 f2019);&lt;/PRE&gt;
&lt;P&gt;if it "worked" , (no problem with the endloop/ennloop definitions) would only have output for the first two sets. IF they are in the WORK library.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When debugging macro code you generally start by setting OPTIONS MPRINT; before running the macro to get the code generated by the macro in the Log and read the log for the details.&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/16488"&gt;@juliajulia&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;i have about 30 datasets that i need to write a macro to get the proc contents from each dataset. i am new to the macro. i write the following but it doesn't work. can any expert take a look at my code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro C1 (ennloop, list);&lt;BR /&gt;%do i = 1 %to &amp;amp;endloop.; &lt;BR /&gt;%let dem = %scan(&amp;amp;list., &amp;amp;i.);&lt;BR /&gt;proc contents data=&amp;amp;list;&lt;BR /&gt;run;&lt;BR /&gt;end;&lt;BR /&gt;%mend;&lt;BR /&gt;%C1(2, c2010 c2016 d2016 d2017 f2016 f2019);&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 15:57:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-write-a-loop-macro-to-proc-contents-for-a-set-of-datasets/m-p/833653#M35787</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-09-15T15:57:14Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a loop macro to proc contents for a set of datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-write-a-loop-macro-to-proc-contents-for-a-set-of-datasets/m-p/833715#M35795</link>
      <description>Thank you for your response.&lt;BR /&gt;would you please explain more? i still can't make it work. i edited the code like this:&lt;BR /&gt;%macro C1 (list);&lt;BR /&gt;%do i = %sysfunc(countw(&amp;amp;list.));&lt;BR /&gt;%let dem = %scan(&amp;amp;list., &amp;amp;i.);&lt;BR /&gt;proc contents data=&amp;amp;list;&lt;BR /&gt;run;&lt;BR /&gt;end;&lt;BR /&gt;%mend;&lt;BR /&gt;%C1( c2010 c2016 d2016 d2017 f2016 f2019);</description>
      <pubDate>Thu, 15 Sep 2022 19:48:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-write-a-loop-macro-to-proc-contents-for-a-set-of-datasets/m-p/833715#M35795</guid>
      <dc:creator>juliajulia</dc:creator>
      <dc:date>2022-09-15T19:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a loop macro to proc contents for a set of datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-write-a-loop-macro-to-proc-contents-for-a-set-of-datasets/m-p/833716#M35796</link>
      <description>there are about 50 files in the folder but i only want to proc contents for 20 of them. so the _all_ is not applicable.</description>
      <pubDate>Thu, 15 Sep 2022 19:50:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-write-a-loop-macro-to-proc-contents-for-a-set-of-datasets/m-p/833716#M35796</guid>
      <dc:creator>juliajulia</dc:creator>
      <dc:date>2022-09-15T19:50:25Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a loop macro to proc contents for a set of datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-write-a-loop-macro-to-proc-contents-for-a-set-of-datasets/m-p/833721#M35798</link>
      <description>&lt;P&gt;Check out the table sashelp.vtable and sashelp.vcolumn in your SAS installation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It has the same metadata as proc contents and querying those tables is often easier than looping proc contents.&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/16488"&gt;@juliajulia&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;there are about 50 files in the folder but i only want to proc contents for 20 of them. so the _all_ is not applicable.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 20:05:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-write-a-loop-macro-to-proc-contents-for-a-set-of-datasets/m-p/833721#M35798</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-09-15T20:05:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a loop macro to proc contents for a set of datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-write-a-loop-macro-to-proc-contents-for-a-set-of-datasets/m-p/833723#M35799</link>
      <description>&lt;P&gt;You need to use DEM on your PROC CONTENTS statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro C1 (list);
%do i = %sysfunc(countw(&amp;amp;list.));
%let dem = %scan(&amp;amp;list., &amp;amp;i.);
proc contents data=&amp;amp;dem;
run;
end;
%mend;
%C1( c2010 c2016 d2016 d2017 f2016 f2019);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Sep 2022 20:07:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-write-a-loop-macro-to-proc-contents-for-a-set-of-datasets/m-p/833723#M35799</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-09-15T20:07:02Z</dc:date>
    </item>
    <item>
      <title>Re: how to write a loop macro to proc contents for a set of datasets</title>
      <link>https://communities.sas.com/t5/New-SAS-User/how-to-write-a-loop-macro-to-proc-contents-for-a-set-of-datasets/m-p/833725#M35800</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro C1(list);

     %let ndsets = %sysfunc(countw(&amp;amp;list.));
  
     %do i = 1 %to &amp;amp;ndsets;
              %let dem = %scan(&amp;amp;list., &amp;amp;i.);
      
               proc contents data=&amp;amp;dem;
               run;

      %end;

%mend;

%C1( c2010 c2016 d2016 d2017 f2016 f2019);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That should run.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Issues:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;%DO loop syntax is incorrect for a loop (just one value)&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;No %END for ending macro loop&lt;/LI&gt;
&lt;LI&gt;Reference &amp;amp;list instead of the &amp;amp;dem variable&lt;/LI&gt;
&lt;/UL&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/16488"&gt;@juliajulia&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Thank you for your response.&lt;BR /&gt;would you please explain more? i still can't make it work. i edited the code like this:&lt;BR /&gt;%macro C1 (list);&lt;BR /&gt;%do i = %sysfunc(countw(&amp;amp;list.));&lt;BR /&gt;%let dem = %scan(&amp;amp;list., &amp;amp;i.);&lt;BR /&gt;proc contents data=&amp;amp;list;&lt;BR /&gt;run;&lt;BR /&gt;end;&lt;BR /&gt;%mend;&lt;BR /&gt;%C1( c2010 c2016 d2016 d2017 f2016 f2019);&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 20:10:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/how-to-write-a-loop-macro-to-proc-contents-for-a-set-of-datasets/m-p/833725#M35800</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-09-15T20:10:41Z</dc:date>
    </item>
  </channel>
</rss>

