<?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: Do Loop Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Macro/m-p/484701#M287089</link>
    <description>&lt;P&gt;I am working on windows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I check one particualr dataset volume from want dataset just to make sure that its reading right.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example : From want dataset if I want to read only&amp;nbsp;&amp;nbsp;data_jan_201800114 how can I approach this.&lt;/P&gt;</description>
    <pubDate>Tue, 07 Aug 2018 11:32:42 GMT</pubDate>
    <dc:creator>sanjay1</dc:creator>
    <dc:date>2018-08-07T11:32:42Z</dc:date>
    <item>
      <title>Do Loop Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Macro/m-p/484658#M287087</link>
      <description>&lt;P&gt;&lt;BR /&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a library with many datasets of same variables. I am tryng to count the number of observations of each dataset by names and place them in a master dataset(result).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below are the datsets which ends with daykey.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;libname ab "/c:/users/desktop/files";&lt;/P&gt;&lt;P&gt;data_201800107&lt;BR /&gt;data_201800114&lt;BR /&gt;data_201800121&lt;BR /&gt;data_201800128&lt;BR /&gt;data_201800207&lt;BR /&gt;data_201800214&lt;BR /&gt;data_201800221&lt;BR /&gt;data_201800228&lt;BR /&gt;data_201800302&lt;BR /&gt;data_201800309&lt;BR /&gt;data_201800316&lt;BR /&gt;data_201800323&lt;BR /&gt;data_201800320&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I can do this with the below code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data result;&lt;BR /&gt;if _n_ = 1 then delete;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%macro test;&lt;BR /&gt;%do i = 0 %to 87;&lt;BR /&gt;data _NULL_;&lt;BR /&gt;OFFSET1=&amp;amp;i;&lt;BR /&gt;X1=PUT(DAY(INTNX('Day',TODAY(),-(OFFSET1+0),'b')),Z2.);&lt;BR /&gt;y1=PUT(MONTH(INTNX('Day',TODAY(),-(OFFSET1+0),'b')),Z2.);&lt;BR /&gt;z1=PUT(YEAR(INTNX('Day',TODAY(),-(OFFSET1+0),'b')),$4.);&lt;BR /&gt;dayk=z1||y1||x1;&lt;BR /&gt;call symput("dayk",dayk);&lt;BR /&gt;run;&lt;BR /&gt;%put &amp;amp;dayk;&lt;/P&gt;&lt;P&gt;%if %sysfunc(exist(ab.data_&amp;amp;dayk.)) %then %do;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table new_&amp;amp;dayk. as&lt;BR /&gt;select count(*) as count,name, from ab.data_&amp;amp;dayk.&lt;BR /&gt;group by name;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;data new_&amp;amp;dayk.;&lt;BR /&gt;set new_&amp;amp;dayk.;&lt;BR /&gt;rundate = "&amp;amp;dayk.";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data result; /*for master data creation */&lt;BR /&gt;set result new_&amp;amp;dayk.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%mend test;&lt;/P&gt;&lt;P&gt;%test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when&amp;nbsp; these data sets have month and date how can I do this.&lt;/P&gt;&lt;P&gt;Below are the sample datasets.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;libname ab "/c:/users/desktop/files";&lt;/P&gt;&lt;P&gt;data_jan_201800107&lt;BR /&gt;data_jan_201800114&lt;BR /&gt;data_jan_201800121&lt;BR /&gt;data_jan_201800128&lt;BR /&gt;data_feb_201800207&lt;BR /&gt;data_feb_201800214&lt;BR /&gt;data_feb_201800221&lt;BR /&gt;data_feb_201800228&lt;BR /&gt;data_mar_201800302&lt;BR /&gt;data_mar_201800309&lt;BR /&gt;data_mar_201800316&lt;BR /&gt;data_mar_201800323&lt;BR /&gt;data_mar_201800320&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks &amp;amp; Regards&lt;/P&gt;&lt;P&gt;Sanjay&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 08:59:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Macro/m-p/484658#M287087</guid>
      <dc:creator>sanjay1</dc:creator>
      <dc:date>2018-08-07T08:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Macro/m-p/484661#M287088</link>
      <description>&lt;P&gt;You do not need to do any of that:&lt;/P&gt;
&lt;PRE&gt;data want;
  set sashelp.vtable (where=(libname="AB") keep=libname memname nobs);
run;&lt;/PRE&gt;
&lt;P&gt;Two tips, if you start creating lots of macro to process your data then consider that you have modelled your data in a less than optimal way.&amp;nbsp; Putting data in dataset names is not a good idea, its makes all your programming effort a lot more difficult and less robust.&amp;nbsp; Also takes more space.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Oh, I just noticed you want by groups not overall, so change to:&lt;/P&gt;
&lt;PRE&gt;data want;
  length dataset $200;
  set ab.data_: indsname=tmp;
  dataset=tmp;
run;

proc sql;
  create table want as
  select dataset,
         name,
         place,
         count(*) as tot
   from  want
   group by dataset,
            name,
            place;
quit;&lt;/PRE&gt;
&lt;P&gt;You will note that I put all the data together - and you will see how much simpler this makes coding.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note that the syntax:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;libname ab "/c:/users/desktop/files";&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Is invalid, are you working on Windows, or UE version or something?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 09:10:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Macro/m-p/484661#M287088</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-07T09:10:19Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Macro/m-p/484701#M287089</link>
      <description>&lt;P&gt;I am working on windows.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I check one particualr dataset volume from want dataset just to make sure that its reading right.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example : From want dataset if I want to read only&amp;nbsp;&amp;nbsp;data_jan_201800114 how can I approach this.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Aug 2018 11:32:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Macro/m-p/484701#M287089</guid>
      <dc:creator>sanjay1</dc:creator>
      <dc:date>2018-08-07T11:32:42Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loop Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Macro/m-p/484706#M287090</link>
      <description>&lt;P&gt;In my code, you can filter the dataset with a where clause, or just look at the sumarised data or if its just one dataset you want to look at rather than using prefix:, just put the dataset name e.g:&lt;/P&gt;
&lt;PRE&gt;data want;
  length dataset $200;
  set ab.data_jan_201800114 indsname=tmp;
  dataset=tmp;
run;

proc sql;
  create table want as
  select dataset,
         name,
         place,
         count(*) as tot
   from  want
   group by dataset,
            name,
            place;
quit;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Aug 2018 11:52:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-Loop-Macro/m-p/484706#M287090</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-07T11:52:00Z</dc:date>
    </item>
  </channel>
</rss>

