<?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 VAriable strips leading zero in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/MAcro-VAriable-strips-leading-zero/m-p/61177#M13271</link>
    <description>Another simple solution is this case is to use 200905 and 200906.</description>
    <pubDate>Tue, 04 Aug 2009 17:41:02 GMT</pubDate>
    <dc:creator>advoss</dc:creator>
    <dc:date>2009-08-04T17:41:02Z</dc:date>
    <item>
      <title>MAcro VAriable strips leading zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MAcro-VAriable-strips-leading-zero/m-p/61174#M13268</link>
      <description>Wondering if someone could help me with the following:&lt;BR /&gt;
&lt;BR /&gt;
rsubmit;&lt;BR /&gt;
%let date1=0905;&lt;BR /&gt;
%let date2=0906;&lt;BR /&gt;
endrsubmit;&lt;BR /&gt;
&lt;BR /&gt;
rsubmit;&lt;BR /&gt;
%macro Asset_history( Start= , Stop= ); &lt;BR /&gt;
&lt;BR /&gt;
%do j = &amp;amp;Start %to &amp;amp;Stop; &lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table HH_Assets_&amp;amp;j as&lt;BR /&gt;
select nnn, cddd, sum(aaaa) as value_&amp;amp;j,sum(bbb) as qty_&amp;amp;j,&lt;BR /&gt;
from XYZ.part&amp;amp;j inner join Elig_secs  on &lt;BR /&gt;
part&amp;amp;j..id=Elig_secs.id&lt;BR /&gt;
and aaa &amp;gt; 0 and cdd='A'&lt;BR /&gt;
group by nnn,cdd,&lt;BR /&gt;
order by nnn,cdd;&lt;BR /&gt;
quit;&lt;BR /&gt;
proc sort data = HH_Assets_&amp;amp;j; by nnn cdd; quit;&lt;BR /&gt;
&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend;&lt;BR /&gt;
endrsubmit;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
rsubmit;&lt;BR /&gt;
%Asset_history( Start=&amp;amp;date1 , Stop=&amp;amp;date2);&lt;BR /&gt;
endrsubmit;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
I keep getting an error message - it strips the leading zero. Could someone please help!</description>
      <pubDate>Mon, 03 Aug 2009 14:14:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MAcro-VAriable-strips-leading-zero/m-p/61174#M13268</guid>
      <dc:creator>SAS09</dc:creator>
      <dc:date>2009-08-03T14:14:51Z</dc:date>
    </item>
    <item>
      <title>Re: MAcro VAriable strips leading zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MAcro-VAriable-strips-leading-zero/m-p/61175#M13269</link>
      <description>Hi:&lt;BR /&gt;
  As it says in the doc:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a000208971.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a000208971.htm&lt;/A&gt;&lt;BR /&gt;
"All parts of the macro language that evaluate expressions (for example, %IF and %DO statements) call %EVAL to evaluate the condition. " &lt;BR /&gt;
&lt;BR /&gt;
And, if you look at the %DO documentation, &lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a000543755.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a000543755.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
you will see that the start and stop values for %DO must resolve to be:&lt;BR /&gt;
"...specify integers or macro expressions that generate integers to control the number of times the portion of the macro between the iterative %DO and %END statements is processed."&lt;BR /&gt;
 &lt;BR /&gt;
Therefore, the string 0905 as an INTEGER number is 905.&lt;BR /&gt;
 &lt;BR /&gt;
You can prove this to yourself by turning on the macro debugging options:&lt;BR /&gt;
options symbolgen mprint mlogic;&lt;BR /&gt;
 &lt;BR /&gt;
I'm betting you will see that &amp;amp;START and &amp;amp;STOP still have the leading 0, but that &amp;amp;J (since it must resolve to an integer number) will be either 905 or 906.&lt;BR /&gt;
 &lt;BR /&gt;
That means you will have to control how &amp;amp;J gets used in building your filenames and variable names. Probably you will need to create another macro variable one that you would use just in the names.&lt;BR /&gt;
&lt;BR /&gt;
cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
options mprint symbolgen mlogic;&lt;BR /&gt;
%macro Asset_history( Start= , Stop= ); &lt;BR /&gt;
              &lt;BR /&gt;
%do j = &amp;amp;Start %to &amp;amp;Stop; &lt;BR /&gt;
                      &lt;BR /&gt;
** put 0 in MYJ for use in names;&lt;BR /&gt;
%let myj = %sysfunc(putn(&amp;amp;j,z4.));&lt;BR /&gt;
%put ***** myj= &amp;amp;myj;&lt;BR /&gt;
                    &lt;BR /&gt;
proc sql;&lt;BR /&gt;
  create table HH_Assets_&amp;amp;myj as&lt;BR /&gt;
 .... use &amp;amp;myj instead of &amp;amp;j in the names ... &lt;BR /&gt;
quit;&lt;BR /&gt;
            &lt;BR /&gt;
... rest of code ...&lt;BR /&gt;
%end;&lt;BR /&gt;
                           &lt;BR /&gt;
%mend;&lt;BR /&gt;
                         &lt;BR /&gt;
** test with more values;&lt;BR /&gt;
%let date1=0905;&lt;BR /&gt;
%let date2=0908;&lt;BR /&gt;
%Asset_history( Start=&amp;amp;date1 , Stop=&amp;amp;date2);&lt;BR /&gt;
[/pre]</description>
      <pubDate>Mon, 03 Aug 2009 18:04:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MAcro-VAriable-strips-leading-zero/m-p/61175#M13269</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-08-03T18:04:24Z</dc:date>
    </item>
    <item>
      <title>Re: MAcro VAriable strips leading zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MAcro-VAriable-strips-leading-zero/m-p/61176#M13270</link>
      <description>Thank you Cynthia!!</description>
      <pubDate>Mon, 03 Aug 2009 18:31:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MAcro-VAriable-strips-leading-zero/m-p/61176#M13270</guid>
      <dc:creator>SAS09</dc:creator>
      <dc:date>2009-08-03T18:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: MAcro VAriable strips leading zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MAcro-VAriable-strips-leading-zero/m-p/61177#M13271</link>
      <description>Another simple solution is this case is to use 200905 and 200906.</description>
      <pubDate>Tue, 04 Aug 2009 17:41:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MAcro-VAriable-strips-leading-zero/m-p/61177#M13271</guid>
      <dc:creator>advoss</dc:creator>
      <dc:date>2009-08-04T17:41:02Z</dc:date>
    </item>
    <item>
      <title>Re: MAcro VAriable strips leading zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MAcro-VAriable-strips-leading-zero/m-p/61178#M13272</link>
      <description>For what it is worth:&lt;BR /&gt;
This brings up a second reason this code bugs me.  Is "0905"  May 2009 or September 5?  If the latter what happens to the code on Sept 30?  Stepping through a string as if it is an integer just seems full of potential problems to me.</description>
      <pubDate>Tue, 04 Aug 2009 18:14:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MAcro-VAriable-strips-leading-zero/m-p/61178#M13272</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-08-04T18:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: MAcro VAriable strips leading zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MAcro-VAriable-strips-leading-zero/m-p/61179#M13273</link>
      <description>Thank you all for your feedback. The sas input datasets have the suffix yymm and therefore I am forced to adopt the formats listed above. Cynthia's suggestion worked like a charm!</description>
      <pubDate>Tue, 04 Aug 2009 23:31:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MAcro-VAriable-strips-leading-zero/m-p/61179#M13273</guid>
      <dc:creator>SAS09</dc:creator>
      <dc:date>2009-08-04T23:31:30Z</dc:date>
    </item>
    <item>
      <title>Re: MAcro VAriable strips leading zero</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MAcro-VAriable-strips-leading-zero/m-p/61180#M13274</link>
      <description>Just a tad curious what you will do when crossing a year boundary, where one string is not in the same year as the other?  &lt;BR /&gt;
&lt;BR /&gt;
Suggest you still take in the two macro variables but drive the %DO / %END process using SAS DATE values represented as macro variables, and then truncate the output format of your low "yymm" and high "yymm" data strings as needed.&lt;BR /&gt;
&lt;BR /&gt;
This would mean using %SYSFUNC and PUTN / INPUTN to convert the yymm to yymm01, using INPUTN and then use PUTN, if needed, to generate a truncated DATE variable string.  You will need to consider using the INTNX function for your processing, possibly.&lt;BR /&gt;
&lt;BR /&gt;
Some examples:&lt;BR /&gt;
&lt;BR /&gt;
%LET YYMM = 0905;&lt;BR /&gt;
%LET MYDATE = %SYSFUNC(INPUTN(&amp;amp;YYMM.01,YYMMDD.));&lt;BR /&gt;
%LET MYDDMMYYYY = %SYSFUNC(PUTN(&amp;amp;MYDATE,DATE7.));&lt;BR /&gt;
%LET MYYYMM = %SYSFUNC(PUTN(&amp;amp;MYDATE,YYMMN4.));&lt;BR /&gt;
%PUT _USER_;&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Wed, 05 Aug 2009 01:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MAcro-VAriable-strips-leading-zero/m-p/61180#M13274</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-08-05T01:22:13Z</dc:date>
    </item>
  </channel>
</rss>

