<?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: Question on iterative macro processing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Question-on-iterative-macro-processing/m-p/96305#M20314</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Tom and Astounding,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It works! Thanks a lot for your help guys.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I used the code Tom provided me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rishi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 07 Jun 2013 08:19:12 GMT</pubDate>
    <dc:creator>RishiThakur</dc:creator>
    <dc:date>2013-06-07T08:19:12Z</dc:date>
    <item>
      <title>Question on iterative macro processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-on-iterative-macro-processing/m-p/96302#M20311</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;After transposing a column on weeks I would like to have it sorted properly. The columns are named wk201301, wk201302 till the current week.&lt;/P&gt;&lt;P&gt;I have written a code which adds the weeknumbers so I can use it in a retain step to sort the columns of week like this:&lt;/P&gt;&lt;P&gt;data test2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retain wk201301, wk201302, wk201303, wk201304;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set test;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It is too intensive to have this code manually so I have made a macro which does this for me:&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; select count(*)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; into :NObs&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from test;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; select vname&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; into :week1-:week&amp;amp;NObs&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from test;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;except the macro is not working as it doesn't count the macro till the week it should do in this case week 21. So that I can use it in a datastep to sort the columns like:&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;retain &amp;amp;week1-&amp;amp;weekx;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;set datasetx;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can I fix this so that the macro creates week1 till week21? Any help would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rishi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Jun 2013 13:07:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-on-iterative-macro-processing/m-p/96302#M20311</guid>
      <dc:creator>RishiThakur</dc:creator>
      <dc:date>2013-06-05T13:07:41Z</dc:date>
    </item>
    <item>
      <title>Re: Question on iterative macro processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-on-iterative-macro-processing/m-p/96303#M20312</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The first problem you are hitting is that &amp;amp;NOBS has the wrong value in it.&amp;nbsp; It contains leading blanks.&amp;nbsp; So you would be getting an error trying to code the equivalent of:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;into : week1 - week&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 21&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are two easy ways to fix this.&amp;nbsp; Pick one ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Insert between the two PROC SQLs:&amp;nbsp; %let nobs = &amp;amp;nobs;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Change the second PROC SQL:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;into : week1 - week&amp;amp;sqlobs&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sometimes taking care of the first problem fixes the rest, sometimes not.&amp;nbsp; If that doesn't take care of it, it would be helpful to see the results of %PUT &amp;amp;NOBS;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Jun 2013 13:27:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-on-iterative-macro-processing/m-p/96303#M20312</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-06-05T13:27:57Z</dc:date>
    </item>
    <item>
      <title>Re: Question on iterative macro processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-on-iterative-macro-processing/m-p/96304#M20313</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Syntax on RETAIN statement does not use commas.&lt;/P&gt;&lt;P&gt;No you know where to get the variable names?&amp;nbsp; In your example you are pulling from a variable named VNAME in a table named TEST, but then you are using that same table as the one that has actual data with the WKxxxxxx variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Once you have the variable names as data then you can use the SEPARATED BY clause on INTO store all of the names into one macro variable. (Note there are limits to the length of a macro variable).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;proc sql noprint;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;&amp;nbsp; select vname into :varlist separated by ' '&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff; font-family: 'courier new', courier; font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from test&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff; font-family: 'courier new', courier; font-size: 10pt; line-height: 1.5em;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;data want ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;&amp;nbsp; retain &amp;amp;varlist;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;&amp;nbsp; set have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;If you want to query the variables in the source dataset then you can use DICTIONARY.COLUMN view.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;proc sql noprint;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;&amp;nbsp; select name into :varlist separated by ' '&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff; font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from dictionary.column&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff; font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; where libname='WORK' and memname='HAVE'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff; font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; and upcase(name) like 'WK%'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff; font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; order by upcase(name)&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #ffffff; font-family: 'courier new', courier; font-size: 10pt;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier; background-color: #ffffff;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Jun 2013 17:10:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-on-iterative-macro-processing/m-p/96304#M20313</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-06-05T17:10:25Z</dc:date>
    </item>
    <item>
      <title>Re: Question on iterative macro processing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question-on-iterative-macro-processing/m-p/96305#M20314</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Tom and Astounding,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It works! Thanks a lot for your help guys.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I used the code Tom provided me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rishi&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Jun 2013 08:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question-on-iterative-macro-processing/m-p/96305#M20314</guid>
      <dc:creator>RishiThakur</dc:creator>
      <dc:date>2013-06-07T08:19:12Z</dc:date>
    </item>
  </channel>
</rss>

