<?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: %let statement problem in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/let-statement-problem/m-p/53840#M14902</link>
    <description>But thing is i need the single quote too... i mean i want mm_bdate to have the value '01May09'd (with the single quote) ...  how do i do this i have tried like this &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%let mm_bdate = "'&amp;amp;v_bddmmmyy'"d;&lt;BR /&gt;
&lt;BR /&gt;
i got this result&lt;BR /&gt;
&lt;BR /&gt;
8           put "The value of Current Month is : &amp;amp;mm_bdate";&lt;BR /&gt;
9          &lt;BR /&gt;
10         &lt;BR /&gt;
&lt;BR /&gt;
The value of Current Month is : 01May09d&lt;BR /&gt;
&lt;BR /&gt;
single quotes was missing.. how do i solve this problem?</description>
    <pubDate>Mon, 13 Jul 2009 11:59:32 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-07-13T11:59:32Z</dc:date>
    <item>
      <title>%let statement problem</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/let-statement-problem/m-p/53838#M14900</link>
      <description>i have this simple program which is giving me a headach,  this variable mm_bdate resolves correctly to '01May09'd, when i use it in a PUT statement... but when the same variable when used in select statement it resolves to '&amp;amp;v_bddmmmyy'd and gives me eros.. please help here....  i have copied my program and the output from the log file for reference... thanks&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
libname ext '/home/nbk6cst/Newapp';&lt;BR /&gt;
&lt;BR /&gt;
%let v_bddmmmyy=01May09 ;&lt;BR /&gt;
&lt;BR /&gt;
%let mm_bdate = '&amp;amp;v_bddmmmyy'd; &lt;BR /&gt;
&lt;BR /&gt;
data _null_;&lt;BR /&gt;
 put "The value of Current Month is : &amp;amp;mm_bdate";&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Proc sql;&lt;BR /&gt;
create table ext.cfc_loss_amt as&lt;BR /&gt;
select &lt;BR /&gt;
accno,&lt;BR /&gt;
sum(chargeoff)                      as chargeoff,&lt;BR /&gt;
sum(contra_chargeoff)               as contra_chargeoff,&lt;BR /&gt;
sum( recovery)                      as recovery,&lt;BR /&gt;
sum(net_charge_off_s)               as net_Charge_off_s&lt;BR /&gt;
from ext.loss &lt;BR /&gt;
where product not in ('CL_PRM') and ( month &amp;gt;= &amp;amp;mm_bdate)&lt;BR /&gt;
group by accno&lt;BR /&gt;
order by accno;&lt;BR /&gt;
quit;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
From LOG&lt;BR /&gt;
---------------&lt;BR /&gt;
&lt;BR /&gt;
8           put "The value of Current Month is : &amp;amp;mm_bdate";&lt;BR /&gt;
9          &lt;BR /&gt;
10         &lt;BR /&gt;
&lt;BR /&gt;
The value of Current Month is : '01May09'd&lt;BR /&gt;
&lt;BR /&gt;
19         from ext.loss&lt;BR /&gt;
20         where product not in ('CL_PRM') and ( month &amp;gt;= &amp;amp;mm_bdate.)&lt;BR /&gt;
ERROR: Invalid date/time/datetime constant '&amp;amp;v_bddmmmyy'd.&lt;BR /&gt;
21         group by accno&lt;BR /&gt;
22         order by accno;</description>
      <pubDate>Mon, 13 Jul 2009 07:24:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/let-statement-problem/m-p/53838#M14900</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-07-13T07:24:46Z</dc:date>
    </item>
    <item>
      <title>Re: %let statement problem</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/let-statement-problem/m-p/53839#M14901</link>
      <description>Single quote versus double quote problem.&lt;BR /&gt;
&lt;BR /&gt;
You should be aware that nothing gets resolved between single quotes.&lt;BR /&gt;
&lt;BR /&gt;
put "The value of Current Month is : &amp;amp;mm_bdate";&lt;BR /&gt;
&lt;BR /&gt;
is resolved because expression is between double quotes.&lt;BR /&gt;
&lt;BR /&gt;
...( month &amp;gt;= &amp;amp;mm_bdate)&lt;BR /&gt;
&lt;BR /&gt;
is not resolved because expression is between single quotes.&lt;BR /&gt;
&lt;BR /&gt;
so, try this instead:&lt;BR /&gt;
&lt;BR /&gt;
%let mm_bdate = "&amp;amp;v_bddmmmyy"d; &lt;BR /&gt;
&lt;BR /&gt;
and loose your put statement (to avoiding double double quoting problems).&lt;BR /&gt;
&lt;BR /&gt;
Cheers from Portugal.&lt;BR /&gt;
&lt;BR /&gt;
Daniel Santos @ &lt;A href="http://www.cgd.pt" target="_blank"&gt;www.cgd.pt&lt;/A&gt;.</description>
      <pubDate>Mon, 13 Jul 2009 09:35:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/let-statement-problem/m-p/53839#M14901</guid>
      <dc:creator>DanielSantos</dc:creator>
      <dc:date>2009-07-13T09:35:53Z</dc:date>
    </item>
    <item>
      <title>Re: %let statement problem</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/let-statement-problem/m-p/53840#M14902</link>
      <description>But thing is i need the single quote too... i mean i want mm_bdate to have the value '01May09'd (with the single quote) ...  how do i do this i have tried like this &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
%let mm_bdate = "'&amp;amp;v_bddmmmyy'"d;&lt;BR /&gt;
&lt;BR /&gt;
i got this result&lt;BR /&gt;
&lt;BR /&gt;
8           put "The value of Current Month is : &amp;amp;mm_bdate";&lt;BR /&gt;
9          &lt;BR /&gt;
10         &lt;BR /&gt;
&lt;BR /&gt;
The value of Current Month is : 01May09d&lt;BR /&gt;
&lt;BR /&gt;
single quotes was missing.. how do i solve this problem?</description>
      <pubDate>Mon, 13 Jul 2009 11:59:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/let-statement-problem/m-p/53840#M14902</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-07-13T11:59:32Z</dc:date>
    </item>
    <item>
      <title>Re: %let statement problem</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/let-statement-problem/m-p/53841#M14903</link>
      <description>Hi:&lt;BR /&gt;
It is generally a bad idea to "prequote" your macro variable values in the %LET statement. The quotes belong to the WHERE clause...&lt;BR /&gt;
 &lt;BR /&gt;
This is perfectly valid SAS code:&lt;BR /&gt;
                  &lt;BR /&gt;
[pre]&lt;BR /&gt;
where birthday = "15Nov1950"d;&lt;BR /&gt;
%let bday = 15Nov1950;&lt;BR /&gt;
where birthday = "&amp;amp;bday"d;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
          &lt;BR /&gt;
the quotes around your date constant can be either single or double quotes. Putting the quotes, where they belong, in the WHERE statement or &lt;BR /&gt;
clause, allows you to avoid "pre-quoting".&lt;BR /&gt;
&lt;BR /&gt;
In your original post, you showed a where clause. You wanted quotes in &amp;amp;MM_BDATE:&lt;BR /&gt;
[pre]&lt;BR /&gt;
where product not in ('CL_PRM') and ( month &amp;gt;= &amp;amp;mm_bdate)&lt;BR /&gt;
[/pre]&lt;BR /&gt;
                                                          &lt;BR /&gt;
But, you could just use your &amp;amp;V_BDDMMMYY macro variable with quotes in the WHERE clause or, if you needed to compare a month value to month value, use the macro variable with %SYSFUNC:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
where product not in ('CL_PRM') and ( month &amp;gt;= "&amp;amp;v_bddmmmyy"d)&lt;BR /&gt;
OR&lt;BR /&gt;
where product not in('CL_PRM') and &lt;BR /&gt;
          month &amp;gt;= %sysfunc(month("&amp;amp;v_bddmmmyy"d) )&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Also, you do not need a DATA _NULL_ to show the value of a macro variable. In addition to the regular PUT statement, there is a %PUT statement, which can be used either inside or outside the DATA _NULL_ environment, right after your %LET statements, for example.&lt;BR /&gt;
                                &lt;BR /&gt;
Using %PUT is a great way to verify that your manipulation and setting of macro variables is happening correctly.&lt;BR /&gt;
 &lt;BR /&gt;
For example, if you issued the %LET and %PUT statements shown in the below set of code, you would see the results as I have pasted them from my SAS Log. Note that I do not have a DATA _NULL_ program.&lt;BR /&gt;
 &lt;BR /&gt;
cynthia&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
SAS LOG:&lt;BR /&gt;
38   %let v_bddmmmyy=01May09 ;&lt;BR /&gt;
39&lt;BR /&gt;
40   %let mm_bdate = '&amp;amp;v_bddmmmyy'd;&lt;BR /&gt;
41&lt;BR /&gt;
42   %let dq_bdate = "&amp;amp;v_bddmmmyy"d;&lt;BR /&gt;
43&lt;BR /&gt;
44   %put The value of mm_bdate is : &amp;amp;mm_bdate;&lt;BR /&gt;
The value of mm_bdate is : '&amp;amp;v_bddmmmyy'd&lt;BR /&gt;
45&lt;BR /&gt;
46   %put The value of dq_bdate is: &amp;amp;dq_bdate;&lt;BR /&gt;
The value of dq_bdate is: "01May09"d&lt;BR /&gt;
47&lt;BR /&gt;
48   %put the value of v_bddmmmyy is: &amp;amp;v_bddmmmyy;&lt;BR /&gt;
the value of v_bddmmmyy is: 01May09&lt;BR /&gt;
49&lt;BR /&gt;
50   %put the month of v_bddmmmyy is: %sysfunc(month("&amp;amp;v_bddmmmyy"d));&lt;BR /&gt;
the month of v_bddmmmyy is: 5&lt;BR /&gt;
51&lt;BR /&gt;
52   %put the year of v_bddmmmyy is: %sysfunc(year("&amp;amp;v_bddmmmyy"d));&lt;BR /&gt;
the year of v_bddmmmyy is: 2009&lt;BR /&gt;
53&lt;BR /&gt;
54   %put the word month of v_bddmmmyy is: %substr(&amp;amp;v_bddmmmyy,3,3);&lt;BR /&gt;
the word month of v_bddmmmyy is: May&lt;BR /&gt;
&lt;BR /&gt;
[/pre]</description>
      <pubDate>Mon, 13 Jul 2009 15:52:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/let-statement-problem/m-p/53841#M14903</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-07-13T15:52:05Z</dc:date>
    </item>
    <item>
      <title>Re: %let statement problem</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/let-statement-problem/m-p/53842#M14904</link>
      <description>but still as you showed in your log .. the value of mm_bdate is still '&amp;amp;v_bddmmmyy'd why wont it substitute the value of the v_bddmmmyy and display it as '01May09'd.....  i cant understand that&lt;BR /&gt;
&lt;BR /&gt;
44   %put The value of mm_bdate is : &amp;amp;mm_bdate;&lt;BR /&gt;
The value of mm_bdate is : '&amp;amp;v_bddmmmyy'd&lt;BR /&gt;
&lt;BR /&gt;
when i use this statement&lt;BR /&gt;
&lt;BR /&gt;
%let mm_bdate = '&amp;amp;v_bddmmmyy'd;  here mm_bdate value should assigned only after substituting the value of v_bddmmmyy right? ....  please explain whats happening here..&lt;BR /&gt;
&lt;BR /&gt;
all i want is  mm_bdate value to have  '01May09'd by substituting the value of v_bddmmmyy .. need to know atleast if there are any workaround for this...&lt;BR /&gt;
&lt;BR /&gt;
Sorry for the nooby questions.. i am just learning SAS... thanks for all the replies guys, much appreciated &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Mon, 13 Jul 2009 17:17:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/let-statement-problem/m-p/53842#M14904</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-07-13T17:17:51Z</dc:date>
    </item>
    <item>
      <title>Re: %let statement problem</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/let-statement-problem/m-p/53843#M14905</link>
      <description>Hi:&lt;BR /&gt;
  Macro variables enclosed in SINGLE quotes do not resolve in the macro variable resolution process.&lt;BR /&gt;
&lt;BR /&gt;
  As I said, it is a bad idea to try to "pre-quote" macro variables in your %LET statement. The quotes belong in the WHERE statement, not in the %LET statement. &lt;BR /&gt;
The quotes for a date constant do NOT have to be single quotes.&lt;BR /&gt;
                                                    &lt;BR /&gt;
  If you follow the general rules for creating macro variable references, you would have started with this -working- WHERE statement:&lt;BR /&gt;
                                          &lt;BR /&gt;
[pre]&lt;BR /&gt;
WHERE somevar = 'value' and month ge '01May09'd;&lt;BR /&gt;
--- then you you would have made a macro variable with a %LET and substituted&lt;BR /&gt;
 the macro variable for the text string 01May09 -- that's all. &lt;BR /&gt;
&lt;BR /&gt;
You want that text string treated as a date constant, so the quotes and the d belong to the WHERE statement. &lt;BR /&gt;
&lt;BR /&gt;
Then, you would have changed your program to create &amp;amp;MACVAR and then changed the WHERE to:&lt;BR /&gt;
                                                            &lt;BR /&gt;
%let macvar = 01May09;&lt;BR /&gt;
WHERE somevar = 'value' and month ge "&amp;amp;macvar"d;&lt;BR /&gt;
                                           &lt;BR /&gt;
---with the quotes in the WHERE Statement, where they belong. You only would have needed to change the single quotes &lt;BR /&gt;
from the first WHERE statement to  double quotes for the second version in order for the macro variable to resolve.&lt;BR /&gt;
[/pre]&lt;BR /&gt;
               &lt;BR /&gt;
  I'm sorry if my previous explanation was not clear. As it says here, in the documentation: &lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a001071889.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/a001071889.htm&lt;/A&gt;&lt;BR /&gt;
&lt;B&gt;"Macro variable references that are enclosed in single quotation marks are not resolved."&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
cynthia</description>
      <pubDate>Mon, 13 Jul 2009 19:03:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/let-statement-problem/m-p/53843#M14905</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2009-07-13T19:03:11Z</dc:date>
    </item>
  </channel>
</rss>

