<?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: Call symput not working as expected in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Call-symput-not-working-as-expected/m-p/318171#M69692</link>
    <description>&lt;P&gt;Thank you all for your valuable feedback!&lt;/P&gt;</description>
    <pubDate>Sun, 11 Dec 2016 21:36:37 GMT</pubDate>
    <dc:creator>renjithr</dc:creator>
    <dc:date>2016-12-11T21:36:37Z</dc:date>
    <item>
      <title>Call symput not working as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Call-symput-not-working-as-expected/m-p/318165#M69689</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the below call symput statements, when I run for the first time &amp;amp;st_dt. and &amp;amp;en_dt. wont resolve to actual values, but the second run resolves it. Could you please let me know why?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First run has the warnings in the log saying that &amp;amp;dte1 and &amp;amp;dte2 not resolved but second run has no warnings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt; date1=put(intnx('month',today(),-1,'beginning'),yymmdd10.);&lt;BR /&gt; call symput('dte1',date1);&lt;BR /&gt; call symput ('st_dt',"'&amp;amp;dte1.'");&lt;BR /&gt; date2=put(intnx('month',today(),-1,'e'), yymmdd10.);&lt;BR /&gt; call symput('dte2',date2);&lt;BR /&gt; call symput ('en_dt',"'&amp;amp;dte2.'");&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;run;&lt;BR /&gt;%put &amp;amp;dte1.;&lt;BR /&gt;%put &amp;amp;dte2.;&lt;BR /&gt;%put &amp;amp;st_dt.;&lt;BR /&gt;%put &amp;amp;en_dt.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 data _null_;&lt;BR /&gt;2 date1=put(intnx('month',today(),-1,'beginning'),yymmdd10.);&lt;BR /&gt;3 call symput('dte1',date1);&lt;BR /&gt;4 call symput ('st_dt',"'&amp;amp;dte1.'");&lt;BR /&gt;WARNING: Apparent symbolic reference DTE1 not resolved.&lt;BR /&gt;5 date2=put(intnx('month',today(),-1,'e'), yymmdd10.);&lt;BR /&gt;6 call symput('dte2',date2);&lt;BR /&gt;7 call symput ('en_dt',"'&amp;amp;dte2.'");&lt;BR /&gt;WARNING: Apparent symbolic reference DTE2 not resolved.&lt;BR /&gt;8&lt;BR /&gt;9&lt;BR /&gt;10 run;&lt;/P&gt;
&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt; real time 0.01 seconds&lt;BR /&gt; cpu time 0.01 seconds&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;11 %put &amp;amp;dte1.;&lt;BR /&gt;2016-11-01&lt;BR /&gt;12 %put &amp;amp;dte2.;&lt;BR /&gt;2016-11-30&lt;BR /&gt;13 %put &amp;amp;st_dt.;&lt;BR /&gt;'&amp;amp;dte1.'&lt;BR /&gt;14 %put &amp;amp;en_dt.;&lt;BR /&gt;'&amp;amp;dte2.'&lt;BR /&gt;15 data _null_;&lt;BR /&gt;16 date1=put(intnx('month',today(),-1,'beginning'),yymmdd10.);&lt;BR /&gt;17 call symput('dte1',date1);&lt;BR /&gt;18 call symput ('st_dt',"'&amp;amp;dte1.'");&lt;BR /&gt;19 date2=put(intnx('month',today(),-1,'e'), yymmdd10.);&lt;BR /&gt;20 call symput('dte2',date2);&lt;BR /&gt;21 call symput ('en_dt',"'&amp;amp;dte2.'");&lt;BR /&gt;22&lt;BR /&gt;23&lt;BR /&gt;24 run;&lt;/P&gt;
&lt;P&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt; real time 0.00 seconds&lt;BR /&gt; cpu time 0.00 seconds&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;25 %put &amp;amp;dte1.;&lt;BR /&gt;2016-11-01&lt;BR /&gt;26 %put &amp;amp;dte2.;&lt;BR /&gt;2016-11-30&lt;BR /&gt;27 %put &amp;amp;st_dt.;&lt;BR /&gt;'2016-11-01'&lt;BR /&gt;28 %put &amp;amp;en_dt.;&lt;BR /&gt;'2016-11-30'&lt;/P&gt;</description>
      <pubDate>Sun, 11 Dec 2016 21:10:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Call-symput-not-working-as-expected/m-p/318165#M69689</guid>
      <dc:creator>renjithr</dc:creator>
      <dc:date>2016-12-11T21:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: Call symput not working as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Call-symput-not-working-as-expected/m-p/318167#M69690</link>
      <description>&lt;P&gt;I thought (could be wrong) that the &amp;amp; is executed at complile time and &amp;amp;dte1 and &amp;amp;dte2 don't exist at compile time given it is populated during the datastep&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The reason it works the second time is that the first data step execution has completed and so the macro vars now exist and can be used when you run again.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;so change to&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;date1=put(intnx('month',today(),-1,'beginning'),yymmdd10.);&lt;BR /&gt;call symput('dte1',date1);&lt;BR /&gt;call symput ('st_dt',date1);&lt;BR /&gt;date2=put(intnx('month',today(),-1,'e'), yymmdd10.);&lt;BR /&gt;call symput('dte2',date2);&lt;BR /&gt;call symput ('en_dt', date2);&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;run;&lt;BR /&gt;%put &amp;amp;dte1.;&lt;BR /&gt;%put &amp;amp;dte2.;&lt;BR /&gt;%put &amp;amp;st_dt.;&lt;BR /&gt;%put &amp;amp;en_dt.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Barry&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Dec 2016 20:57:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Call-symput-not-working-as-expected/m-p/318167#M69690</guid>
      <dc:creator>twocanbazza</dc:creator>
      <dc:date>2016-12-12T20:57:24Z</dc:date>
    </item>
    <item>
      <title>Re: Call symput not working as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Call-symput-not-working-as-expected/m-p/318170#M69691</link>
      <description>&lt;P&gt;So, as already stated, you cannot use a macro variable in the same data step you created it. If you really want to, use SYMGET or RESOLVE. But since you already have the variables created you can use them as you did in the other CALL SYMPUT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would recommend, replacing the single quotes with the QUOTE function. I find it's more legible and very clear off the bat what you're trying to do - add quotes, and in this case single quotes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would also recommend CALL SYMPUTX as it removes any trailing spaces which is common when creating macro variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	date1=put(intnx('month', today(), -1, 'beginning'), yymmdd10.);
	date2=put(intnx('month', today(), -1, 'e'), yymmdd10.);
	call symputx('dte1', date1);
	call symputx ('st_dt', quote(date1, "'"));
	call symputx('dte2', date2);
	call symputx ('en_dt', quote(date2, "'"));
run;

%put &amp;amp;dte1.;
%put &amp;amp;dte2.;
%put &amp;amp;st_dt.;
%put &amp;amp;en_dt.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 11 Dec 2016 21:29:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Call-symput-not-working-as-expected/m-p/318170#M69691</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-12-11T21:29:40Z</dc:date>
    </item>
    <item>
      <title>Re: Call symput not working as expected</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Call-symput-not-working-as-expected/m-p/318171#M69692</link>
      <description>&lt;P&gt;Thank you all for your valuable feedback!&lt;/P&gt;</description>
      <pubDate>Sun, 11 Dec 2016 21:36:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Call-symput-not-working-as-expected/m-p/318171#M69692</guid>
      <dc:creator>renjithr</dc:creator>
      <dc:date>2016-12-11T21:36:37Z</dc:date>
    </item>
  </channel>
</rss>

