<?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 erros in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/MAcro-erros/m-p/561585#M10612</link>
    <description>&lt;P&gt;it works, thank you for comprehensive guidance&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 25 May 2019 20:24:54 GMT</pubDate>
    <dc:creator>meckarthik</dc:creator>
    <dc:date>2019-05-25T20:24:54Z</dc:date>
    <item>
      <title>MAcro erros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/MAcro-erros/m-p/561527#M10605</link>
      <description>&lt;P&gt;Hi There,&lt;/P&gt;&lt;P&gt;Need help on&amp;nbsp;Macro error&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i got min and max week number&amp;nbsp; as below.. trying to create table based on week number between &amp;amp;min_weeks and &amp;amp;max_weeks but macro showing error with dot (.) instead of actual number&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc sql ;&lt;/P&gt;&lt;P&gt;select min( week_number)&amp;nbsp; into : MIN_WEEKS&lt;/P&gt;&lt;P&gt;from&amp;nbsp;&amp;nbsp; work.Data&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let MIN_WEEKS = %qtrim(&amp;amp;MIN_WEEKS);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%put &amp;amp;MIN_WEEKS ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc sql ;&lt;/P&gt;&lt;P&gt;select max(week_number)&amp;nbsp; into : MAX_WEEKS&lt;/P&gt;&lt;P&gt;from&amp;nbsp;&amp;nbsp; work.Data;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let MAX_WEEKS = %qtrim(&amp;amp;MAX_WEEKS);&lt;/P&gt;&lt;P&gt;%put &amp;amp;MAX_WEEKS ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;SELECT&amp;nbsp;&amp;nbsp; distinct adj_week_number as weeks&lt;/P&gt;&lt;P&gt;into work.&lt;STRONG&gt;i&lt;/STRONG&gt;ter1&lt;/P&gt;&lt;P&gt;from work.Data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE week_number BETWEEN &amp;amp;MIN_WEEKS. AND &amp;amp;MAX_WEEKS.;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the macro &amp;amp;MIN_WEEKS., &amp;amp;MAX_WEEKS. not working , getting error&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;“WHERE week_number &amp;nbsp;BETWEEN . AND . “ &amp;nbsp;not sure why getting dot instead of number (e.g. 1 – min and 5- max)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 May 2019 01:43:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/MAcro-erros/m-p/561527#M10605</guid>
      <dc:creator>meckarthik</dc:creator>
      <dc:date>2019-05-25T01:43:13Z</dc:date>
    </item>
    <item>
      <title>Re: MAcro erros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/MAcro-erros/m-p/561528#M10606</link>
      <description>&lt;P&gt;Try removing the space between the colon and the macro variable. If that doesn't help post your SAS log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc sql ;

select min( week_number)  into :MIN_WEEKS

from   work.Data;

quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 May 2019 02:19:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/MAcro-erros/m-p/561528#M10606</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-05-25T02:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: MAcro erros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/MAcro-erros/m-p/561530#M10607</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/275095"&gt;@meckarthik&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are syntax errors in the code you've posted so that can't be the version you've executed and then had problems with.&lt;/P&gt;
&lt;P&gt;1. Missing semicolon in the first SQL&lt;/P&gt;
&lt;P&gt;2. "&lt;EM&gt;into work.&lt;STRONG&gt;i&lt;/STRONG&gt;ter1&lt;/EM&gt;" is not valid SAS SQL syntax the way you use it&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is also a logical issue with your code.&lt;/P&gt;
&lt;P&gt;You are selecting the minimum and maximum week_number from the whole table and populate these values into SAS macro variables. You then use these macro variable in a between condition on the exactly same table using the exactly same variable from where you've derived these values. So... this condition will always be true and though is rather useless.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below your code with the syntax errors fixed and posted using the running man icon to not mess-up the code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data;
  do week_number=1 to 5;
    adj_week_number+5;
    output;
  end;
  stop;
run;

Proc sql noprint;
  select min( week_number)  into : MIN_WEEKS
    from   work.Data
  ;
quit;

%let MIN_WEEKS = %qtrim(&amp;amp;MIN_WEEKS);
%put &amp;amp;MIN_WEEKS;

Proc sql noprint;
  select max(week_number)  into : MAX_WEEKS
    from   work.Data
  ;
quit;

%let MAX_WEEKS = %qtrim(&amp;amp;MAX_WEEKS);
%put &amp;amp;MAX_WEEKS;

PROC SQL;
  SELECT   distinct adj_week_number as weeks
      from work.Data
        WHERE week_number BETWEEN &amp;amp;MIN_WEEKS. AND &amp;amp;MAX_WEEKS.;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And as a side note here how you can populate your min &amp;amp; max macro variables in a single SQL and with left aligned values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select 
    put(min(week_number),32. -l),  
    put(max(week_number),32. -l)
      into 
        :min_weeks,
        :max_week
    from work.data
  ;
quit;

%put &amp;amp;=min_weeks;
%put &amp;amp;=max_weeks;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 May 2019 02:16:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/MAcro-erros/m-p/561530#M10607</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-05-25T02:16:24Z</dc:date>
    </item>
    <item>
      <title>Re: MAcro erros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/MAcro-erros/m-p/561537#M10608</link>
      <description>In addition to the many good points already mentioned, only bad things happen when SQL tries to parse quoted strings.  So get rid of %QTRIM.  Instead use:&lt;BR /&gt;&lt;BR /&gt;%let min_weeks = &amp;amp;min_weeks;&lt;BR /&gt;%let max_weeks = &amp;amp;max_weeks;</description>
      <pubDate>Sat, 25 May 2019 05:46:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/MAcro-erros/m-p/561537#M10608</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-05-25T05:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: MAcro erros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/MAcro-erros/m-p/561577#M10610</link>
      <description>&lt;P&gt;A single period is how SAS represents missing numeric values.&amp;nbsp; So if your variable is all missing then both the minimum and the maximum value will be represented by a period.&amp;nbsp; &amp;nbsp;What do you want to do in that case?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you can simplify how you make the macro variables so that they are not created with leading/trailing spaces.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select min( week_number)
       , max(week_number) 
    into :MIN_WEEKS trimmed
       , :MAX_WEEKS trimmed
  from work.Data
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 May 2019 17:31:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/MAcro-erros/m-p/561577#M10610</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-25T17:31:32Z</dc:date>
    </item>
    <item>
      <title>Re: MAcro erros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/MAcro-erros/m-p/561584#M10611</link>
      <description>&lt;P&gt;it works, thank you!&lt;/P&gt;</description>
      <pubDate>Sat, 25 May 2019 20:23:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/MAcro-erros/m-p/561584#M10611</guid>
      <dc:creator>meckarthik</dc:creator>
      <dc:date>2019-05-25T20:23:48Z</dc:date>
    </item>
    <item>
      <title>Re: MAcro erros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/MAcro-erros/m-p/561585#M10612</link>
      <description>&lt;P&gt;it works, thank you for comprehensive guidance&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 May 2019 20:24:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/MAcro-erros/m-p/561585#M10612</guid>
      <dc:creator>meckarthik</dc:creator>
      <dc:date>2019-05-25T20:24:54Z</dc:date>
    </item>
    <item>
      <title>Re: MAcro erros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/MAcro-erros/m-p/561586#M10613</link>
      <description>&lt;P&gt;Thank you!!&lt;/P&gt;</description>
      <pubDate>Sat, 25 May 2019 20:25:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/MAcro-erros/m-p/561586#M10613</guid>
      <dc:creator>meckarthik</dc:creator>
      <dc:date>2019-05-25T20:25:20Z</dc:date>
    </item>
  </channel>
</rss>

