<?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: Inserting macro variable values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Inserting-macro-variable-values/m-p/536699#M147525</link>
    <description>&lt;P&gt;Show us the LOG. Click on the {i} icon and paste the log into the window that appears. DO NOT SKIP THIS STEP.&lt;/P&gt;</description>
    <pubDate>Tue, 19 Feb 2019 11:58:29 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-02-19T11:58:29Z</dc:date>
    <item>
      <title>Inserting macro variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-macro-variable-values/m-p/536632#M147489</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;INSERT INTO PYODS.PY_TierCalcStaging&lt;BR /&gt;(BatchId,ciskey,calcyearmonth,firstname,CustomerStatus,Action,tierid,Tenure,OnlineRegisteredFlag,StaffIndicator,VIPIndicator,TotalCalcPoints,CalcTenureFlag,ProdTranAcctFlag,&lt;BR /&gt;ProdSavingAcctFlag,ProdTermDepositFlag,ProdCreditCardFlag,ProdPersonalLoanFlag,ProdOwnerOccHLFlag,ProdInvestorHLFlag,ProdGeneralInsFlag,ProdSuperFlag,ProdInvestmentFlag,ProdPersonalInsFlag,BehaviourFlagTranFlag,&lt;BR /&gt;BehaviourBanksOnlineFlag,LoadStatus)&lt;/P&gt;&lt;P&gt;SELECT 20190201001,&lt;BR /&gt;ciskey,'201812',firstname,CustomerStatus,Action,tierid,Tenure,OnlineRegisteredFlag,StaffIndicator,VIPIndicator,TotalCalcPoints,CalcTenureFlag,ProdTranAcctFlag,&lt;BR /&gt;ProdSavingAcctFlag,ProdTermDepositFlag,ProdCreditCardFlag,ProdPersonalLoanFlag,ProdOwnerOccHLFlag,ProdInvestorHLFlag,ProdGeneralInsFlag,ProdSuperFlag,ProdInvestmentFlag,ProdPersonalInsFlag,BehaviourFlagTranFlag,&lt;BR /&gt;BehaviourBanksOnlineFlag,LoadStatus&lt;BR /&gt;FROM MYWRLDPY.py_tiercalcstaging;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is working fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I replace the numerics with the macro variable like below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;LIBNAME PYODS SQLSVR DSN=*************** USER='********' PASSWORD='********';&lt;BR /&gt;&lt;BR /&gt;%macro PY_Tiercalc_Staging(Mth);&lt;/P&gt;&lt;P&gt;%let month_key = %str(%')%sysfunc(putn(&amp;amp;mth,6.))%str(%');&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;create table sequence_number as&lt;BR /&gt;select Max(BatchId) as Max_BatchId from PYODS.PY_TierCalcStaging&lt;BR /&gt;where datepart(lastupdatedate)= today();&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;set sequence_number;&lt;BR /&gt;call symput('Seqnum',Max_batchid);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%put &amp;amp;=seqnum;&lt;/P&gt;&lt;P&gt;%if &amp;amp;seqnum=. %then %do;&lt;BR /&gt;%let sequencenum=001;&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;%let Seq_num=%substr(&amp;amp;Seqnum,9,3);&lt;BR /&gt;%let seq_num_new=%eval(&amp;amp;seq_num+1);&lt;BR /&gt;%let sequencenum=%str(%0)%str(%0)&amp;amp;seq_num_new;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%if %length(%sysfunc(month("&amp;amp;sysdate"d))) &amp;lt; 2 %then&lt;BR /&gt;%do;&lt;BR /&gt;%let thismonth=0%sysfunc(month("&amp;amp;sysdate"d));&lt;BR /&gt;%end;&lt;/P&gt;&lt;P&gt;%else %do;&lt;BR /&gt;%let thismonth=%sysfunc(month("&amp;amp;sysdate"d));&lt;BR /&gt;%end;&lt;BR /&gt;%put &amp;amp;=thismonth;&lt;/P&gt;&lt;P&gt;%if %length(%sysfunc(day("&amp;amp;sysdate"d))) &amp;lt; 2 %then&lt;BR /&gt;%do;&lt;BR /&gt;%let thisday=0%sysfunc(day("&amp;amp;sysdate"d));&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;%let thisday=%sysfunc(day("&amp;amp;sysdate"d));&lt;BR /&gt;%end;&lt;BR /&gt;%put &amp;amp;=thisday;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%let batchnum=%sysfunc(year("&amp;amp;sysdate"d))&amp;amp;thismonth.&amp;amp;thisday.&amp;amp;sequencenum.;&lt;/P&gt;&lt;P&gt;%put &amp;amp;=sequencenum;&lt;BR /&gt;%put &amp;amp;=batchnum;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;INSERT INTO PYODS.PY_TierCalcStaging&lt;BR /&gt;(BatchId,ciskey,calcyearmonth,firstname,CustomerStatus,Action,tierid,Tenure,OnlineRegisteredFlag,StaffIndicator,VIPIndicator,TotalCalcPoints,CalcTenureFlag,ProdTranAcctFlag,&lt;BR /&gt;ProdSavingAcctFlag,ProdTermDepositFlag,ProdCreditCardFlag,ProdPersonalLoanFlag,ProdOwnerOccHLFlag,ProdInvestorHLFlag,ProdGeneralInsFlag,ProdSuperFlag,ProdInvestmentFlag,ProdPersonalInsFlag,BehaviourFlagTranFlag,&lt;BR /&gt;BehaviourBanksOnlineFlag,LoadStatus)&lt;/P&gt;&lt;P&gt;SELECT &amp;amp;batchnum.,&lt;BR /&gt;ciskey,&amp;amp;month_key.,firstname,CustomerStatus,Action,tierid,Tenure,OnlineRegisteredFlag,StaffIndicator,VIPIndicator,TotalCalcPoints,CalcTenureFlag,ProdTranAcctFlag,&lt;BR /&gt;ProdSavingAcctFlag,ProdTermDepositFlag,ProdCreditCardFlag,ProdPersonalLoanFlag,ProdOwnerOccHLFlag,ProdInvestorHLFlag,ProdGeneralInsFlag,ProdSuperFlag,ProdInvestmentFlag,ProdPersonalInsFlag,BehaviourFlagTranFlag,&lt;BR /&gt;BehaviourBanksOnlineFlag,LoadStatus&lt;BR /&gt;FROM MYWRLDPY.py_tiercalcstaging;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get the below error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,&lt;BR /&gt;a missing value, (, *, +, -, BTRIM, CALCULATED, CASE, EXISTS, INPUT, NOT, PUT, SUBSTRING, TRANSLATE, USER, ^, ~.&lt;/P&gt;&lt;P&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what's wrong with the code?&lt;/P&gt;</description>
      <pubDate>Tue, 19 Feb 2019 02:12:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-macro-variable-values/m-p/536632#M147489</guid>
      <dc:creator>Swathi12</dc:creator>
      <dc:date>2019-02-19T02:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting macro variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-macro-variable-values/m-p/536699#M147525</link>
      <description>&lt;P&gt;Show us the LOG. Click on the {i} icon and paste the log into the window that appears. DO NOT SKIP THIS STEP.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Feb 2019 11:58:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-macro-variable-values/m-p/536699#M147525</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-19T11:58:29Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting macro variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-macro-variable-values/m-p/536708#M147528</link>
      <description>One known issue:  SQL doesn't resolve %str(%') in time.  After assigning a value to &amp;amp;month_key, you can address the problem by adding &lt;BR /&gt;&lt;BR /&gt;%let month_key = %unquote(&amp;amp;month_key);</description>
      <pubDate>Tue, 19 Feb 2019 12:42:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-macro-variable-values/m-p/536708#M147528</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-19T12:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting macro variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-macro-variable-values/m-p/536712#M147530</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/56625"&gt;@Swathi12&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As addition to what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;replied: I think you have a problem with&amp;nbsp;%let sequencenum=%str(%0)%str(%0)&amp;amp;seq_num_new;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is written to your log from the statement&amp;nbsp;%put &amp;amp;=batchnum;? - if it is something like&amp;nbsp;BATCHNUM=20190219%0%0124, this would give you trouble too. It might be easier to skip all the macro work and calculate/generate the macro variables batchnum and month_key within the data _null_ step.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Feb 2019 13:02:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-macro-variable-values/m-p/536712#M147530</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-02-19T13:02:16Z</dc:date>
    </item>
    <item>
      <title>Re: Inserting macro variable values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Inserting-macro-variable-values/m-p/536764#M147549</link>
      <description>&lt;P&gt;Looks like you need to learn how to use formats for generating the strings.&lt;/P&gt;
&lt;P&gt;You can use the YYMMDDN format to convert a date into an eight character string of digits representing year, month, and day.&lt;/P&gt;
&lt;P&gt;You can use the Z format to convert a number into a string of digits with leading zeros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the macro is already running procs and steps there is no need to try to generate the macro variable value with pure macro code. It is easier to manipulate data using a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So your program might look like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro PY_Tiercalc_Staging(Mth);
%local month_key batchid batchnum ;

proc sql noprint ;
  select max(BatchId) into :BatchId 
    from PYODS.PY_TierCalcStaging
    where datepart(lastupdatedate)= today()
  ;
quit;
data _null_;
  call symputx('month_key',"'&amp;amp;mtn'");
  call symputx('batchnum',cats(put(today(),yymmddn8.),put(&amp;amp;batchid,z3.)));
run;

proc sql;
  insert into PYODS.PY_TierCalcStaging (BatchId,ciskey,calcyearmonth,.....)
  select &amp;amp;batchnum.,ciskey,&amp;amp;month_key.,.....
  from MYWRLDPY.py_tiercalcstaging
;
quit;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Feb 2019 23:02:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Inserting-macro-variable-values/m-p/536764#M147549</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-02-19T23:02:47Z</dc:date>
    </item>
  </channel>
</rss>

