<?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 macro, can not return to the variable defined in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-macro-can-not-return-to-the-variable-defined/m-p/374800#M276379</link>
    <description>&lt;P&gt;Thank you for your reply, Tom.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actually, this is the simplified codes I made, in the real business occasion, I need to use the date_deb, date_fin and MOIS many times later, that's why I need to make it as MACRO.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want is to keep the following macro form, but make the DATA RESULT show all the columns correctly, espacially the col3 and col4. &amp;nbsp;And I already used the SET TEST in the DATA RESULT STEP.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA test;
INPUT ID DATE MMDDYY8.;
DATALINES;
00001 05012017
00002 05032017
00003 05012017
00004 04282017
;
RUN;

%LET date_deb = DATE;
%LET date_fin = INTNX("month",&amp;amp;date_deb,+1,"sameday");

DATA _NULL_;
CALL SYMPUT("MOIS", SUBSTR(put(&amp;amp;date_deb,MMDDYY8.),7,2)!!SUBSTR(put(&amp;amp;date_deb,MMDDYY8.),1,2));
RUN;

DATA result;
SET test;
col1 = &amp;amp;date_deb;
col2 = &amp;amp;date_fin;
col3 = "Iwanttoprint&amp;amp;MOIS.it";
col4 = &amp;amp;MOIS;
col5 = SUBSTR(put(&amp;amp;date_deb,MMDDYY8.),7,2)!!SUBSTR(put(&amp;amp;date_deb,MMDDYY8.),1,2);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm a new user of SAS, hope that I explan my need clearly.&lt;/P&gt;&lt;P&gt;Thank you so much for your kind help.&lt;/P&gt;&lt;P&gt;Vivian&lt;/P&gt;</description>
    <pubDate>Tue, 11 Jul 2017 06:07:42 GMT</pubDate>
    <dc:creator>viviwu</dc:creator>
    <dc:date>2017-07-11T06:07:42Z</dc:date>
    <item>
      <title>CALL SYMPUT macro, can not return to the variable defined</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-macro-can-not-return-to-the-variable-defined/m-p/374728#M276377</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a qustion about the macro and&amp;nbsp;CALL SYMPUT.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my codes:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA test;
INPUT ID DATE MMDDYY8.;
DATALINES;
00001 05012017
00002 05032017
00003 05012017
00004 04282017
;
RUN;

%LET date_deb = DATE;
%LET date_fin = INTNX("month",&amp;amp;date_deb,+1,"sameday");

DATA _NULL_;
CALL SYMPUT("MOIS", SUBSTR(put(&amp;amp;date_deb,MMDDYY8.),7,2)!!SUBSTR(put(&amp;amp;date_deb,MMDDYY8.),1,2));
RUN;

DATA result;
SET test;
col1 = &amp;amp;date_deb;
col2 = &amp;amp;date_fin;
col3 = "Iwanttoprint&amp;amp;MOIS.it";
col4 = &amp;amp;MOIS;
col5 = SUBSTR(put(&amp;amp;date_deb,MMDDYY8.),7,2)!!SUBSTR(put(&amp;amp;date_deb,MMDDYY8.),1,2);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;DIV class=" dgrid-row dgrid-row-even ui-state-default"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Results:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;ID&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;DATE&lt;/P&gt;&lt;P&gt;20940&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;col1&lt;/P&gt;&lt;P&gt;20940&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;col2&lt;/P&gt;&lt;P&gt;20971&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;col3&lt;/P&gt;&lt;P&gt;Iwanttoprint&amp;nbsp;.&amp;nbsp;&amp;nbsp;it&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;col4&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;col5&lt;/P&gt;&lt;P&gt;1705&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;DIV class=" dgrid-row dgrid-row-odd ui-state-default"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;20942&lt;/TD&gt;&lt;TD&gt;20942&lt;/TD&gt;&lt;TD&gt;20973&lt;/TD&gt;&lt;TD&gt;Iwanttoprint&amp;nbsp;.&amp;nbsp;&amp;nbsp;it&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;1705&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;DIV class=" dgrid-row dgrid-row-even ui-state-default"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;20940&lt;/TD&gt;&lt;TD&gt;20940&lt;/TD&gt;&lt;TD&gt;20971&lt;/TD&gt;&lt;TD&gt;Iwanttoprint&amp;nbsp;.&amp;nbsp;&amp;nbsp;it&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;1705&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;DIV class=" dgrid-row ui-state-default dgrid-row-odd dgrid-selected ui-state-active"&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;20937&lt;/TD&gt;&lt;TD&gt;20937&lt;/TD&gt;&lt;TD&gt;20967&lt;/TD&gt;&lt;TD&gt;Iwanttoprint&amp;nbsp;.&amp;nbsp;&amp;nbsp;it&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;1704&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;DIV class=" dgrid-row ui-state-default dgrid-row-odd dgrid-selected ui-state-active"&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My question is why col3 and col4 can not return to the value of 1705/1704? And could you please tell me how to fix it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In order to debug, I tried to replace the %LET date_deb =&amp;nbsp;&lt;SPAN&gt;20940, the codes are as following:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%LET date_deb = 20940;
%LET date_fin = INTNX("month",&amp;amp;date_deb,+1,"sameday");

DATA _NULL_;
CALL SYMPUT("MOIS", SUBSTR(put(&amp;amp;date_deb,MMDDYY8.),7,2)!!SUBSTR(put(&amp;amp;date_deb,MMDDYY8.),1,2));
RUN;

DATA result2;
col1 = &amp;amp;date_deb;
col2 = &amp;amp;date_fin;
col3 = "Iwanttoprint&amp;amp;MOIS.it";
col4 = &amp;amp;MOIS;
col5 = SUBSTR(put(20940,MMDDYY8.),7,2)!!SUBSTR(put(20940,MMDDYY8.),1,2);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Result:&lt;/SPAN&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;ID&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;col1&lt;/P&gt;&lt;P&gt;20940&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;col2&lt;/P&gt;&lt;P&gt;20971&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;col3&lt;/P&gt;&lt;P&gt;Iwanttoprint1705it&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;col4&lt;/P&gt;&lt;P&gt;1705&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;col5&lt;/P&gt;&lt;P&gt;1705&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;And it seems work in this way, but I don't understand why.&lt;/DIV&gt;&lt;DIV class=" dgrid-row ui-state-default dgrid-row-odd dgrid-selected ui-state-active"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=" dgrid-row ui-state-default dgrid-row-odd dgrid-selected ui-state-active"&gt;Thank you in advance.&lt;/DIV&gt;&lt;DIV class=" dgrid-row ui-state-default dgrid-row-odd dgrid-selected ui-state-active"&gt;VIVIAN&lt;/DIV&gt;</description>
      <pubDate>Mon, 10 Jul 2017 22:15:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-macro-can-not-return-to-the-variable-defined/m-p/374728#M276377</guid>
      <dc:creator>viviwu</dc:creator>
      <dc:date>2017-07-10T22:15:07Z</dc:date>
    </item>
    <item>
      <title>Re: CALL SYMPUT macro, can not return to the variable defined</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-macro-can-not-return-to-the-variable-defined/m-p/374742#M276378</link>
      <description>&lt;P&gt;Your macro variable MOIS is missing because you did not give it any date to use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1531  %LET date_deb = DATE;
1532  %LET date_fin = INTNX("month",&amp;amp;date_deb,+1,"sameday");
1533
1534  DATA _NULL_;
1535  CALL SYMPUT("MOIS", SUBSTR(put(&amp;amp;date_deb,MMDDYY8.),7,2)!!SUBSTR(put(&amp;amp;date_deb,MMDDYY8.),1,2));
1536  RUN;

NOTE: Variable DATE is uninitialized.
&lt;/PRE&gt;
&lt;P&gt;When you used similar code in the later data step you have used a SET statement to bring a dataset that actually had a DATE variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are working way too hard. Let SAS generate the value in the form you need directly.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set test ;
  col1 = date;
  col2 = intnx('month',col1,1);
  col4 = put(col2,yymmn4.);
  format date col1 col2 yymmdd10. ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    ID          DATE          col1          col2    col4

 1      1    2017-05-01    2017-05-01    2017-06-01    1706
 2      2    2017-05-03    2017-05-03    2017-06-01    1706
 3      3    2017-05-01    2017-05-01    2017-06-01    1706
 4      4    2017-04-28    2017-04-28    2017-05-01    1705
&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Jul 2017 00:13:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-macro-can-not-return-to-the-variable-defined/m-p/374742#M276378</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-07-11T00:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: CALL SYMPUT macro, can not return to the variable defined</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-macro-can-not-return-to-the-variable-defined/m-p/374800#M276379</link>
      <description>&lt;P&gt;Thank you for your reply, Tom.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actually, this is the simplified codes I made, in the real business occasion, I need to use the date_deb, date_fin and MOIS many times later, that's why I need to make it as MACRO.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want is to keep the following macro form, but make the DATA RESULT show all the columns correctly, espacially the col3 and col4. &amp;nbsp;And I already used the SET TEST in the DATA RESULT STEP.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA test;
INPUT ID DATE MMDDYY8.;
DATALINES;
00001 05012017
00002 05032017
00003 05012017
00004 04282017
;
RUN;

%LET date_deb = DATE;
%LET date_fin = INTNX("month",&amp;amp;date_deb,+1,"sameday");

DATA _NULL_;
CALL SYMPUT("MOIS", SUBSTR(put(&amp;amp;date_deb,MMDDYY8.),7,2)!!SUBSTR(put(&amp;amp;date_deb,MMDDYY8.),1,2));
RUN;

DATA result;
SET test;
col1 = &amp;amp;date_deb;
col2 = &amp;amp;date_fin;
col3 = "Iwanttoprint&amp;amp;MOIS.it";
col4 = &amp;amp;MOIS;
col5 = SUBSTR(put(&amp;amp;date_deb,MMDDYY8.),7,2)!!SUBSTR(put(&amp;amp;date_deb,MMDDYY8.),1,2);
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm a new user of SAS, hope that I explan my need clearly.&lt;/P&gt;&lt;P&gt;Thank you so much for your kind help.&lt;/P&gt;&lt;P&gt;Vivian&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 06:07:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-macro-can-not-return-to-the-variable-defined/m-p/374800#M276379</guid>
      <dc:creator>viviwu</dc:creator>
      <dc:date>2017-07-11T06:07:42Z</dc:date>
    </item>
    <item>
      <title>Re: CALL SYMPUT macro, can not return to the variable defined</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-macro-can-not-return-to-the-variable-defined/m-p/374967#M276380</link>
      <description>&lt;P&gt;If you want to set MOIS to a date, what date do you want to use? &amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you wanted to use the previous month based on the current date then you might use something like.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  call symputx('mois',put(intnx('month',date(),-1),yymmn4.));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could just use macro code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mois=%sysfunc(intnx(month,%sysfunc(date()),-1),yymmn4);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 14:05:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-macro-can-not-return-to-the-variable-defined/m-p/374967#M276380</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-07-11T14:05:24Z</dc:date>
    </item>
    <item>
      <title>Re: CALL SYMPUT macro, can not return to the variable defined</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-macro-can-not-return-to-the-variable-defined/m-p/375227#M276381</link>
      <description>&lt;P&gt;Hello Tom,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think this function returns to the current yymm (1706)&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mois=%sysfunc(intnx(month,%sysfunc(date()),-1),yymmn4);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But in my case, the MOIS is the yymm of the Date I have in the TEST&amp;nbsp;date set which is a list of different date row by row.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date_deb = Date;
%let date_fin = intnx("month",&amp;amp;date_deb,+1,"sameday");&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;In the previous project, they all use this code to extract the yymm from the date_deb, but that date_deb is a fix date like "01MAY2017"d. When I changed date_deb to the list of date, it didn't work anymore.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA _NULL_;
CALL SYMPUTX("MOIS",substr(put(&amp;amp;date_deb.,yymmddn8.),3,2)!!substr(put(&amp;amp;date_beb.,yymmddn8.),5,2));
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Goodday,&lt;/P&gt;&lt;P&gt;Vivian&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 07:58:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-macro-can-not-return-to-the-variable-defined/m-p/375227#M276381</guid>
      <dc:creator>viviwu</dc:creator>
      <dc:date>2017-07-12T07:58:18Z</dc:date>
    </item>
    <item>
      <title>Re: CALL SYMPUT macro, can not return to the variable defined</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-macro-can-not-return-to-the-variable-defined/m-p/375290#M276382</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/111426"&gt;@viviwu&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN&gt;In the previous project, they all use this code to extract the yymm from the date_deb, but that date_deb is a fix date like "01MAY2017"d. When I changed date_deb to the list of date, it didn't work anymore.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA _NULL_;
CALL SYMPUTX("MOIS",substr(put(&amp;amp;date_deb.,yymmddn8.),3,2)!!substr(put(&amp;amp;date_beb.,yymmddn8.),5,2));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I do not understand want you want. If you want to store in the macro variable the code that can generate a string in YYMM format from a date variable then you would want something like.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let datevar=date ;
%let mois=put(&amp;amp;datevar,yymmn4.);
data want ;
  set have ;
  length newvar $4 ;
  newvar = &amp;amp;mois ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Jul 2017 12:43:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-macro-can-not-return-to-the-variable-defined/m-p/375290#M276382</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-07-12T12:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: CALL SYMPUT macro, can not return to the variable defined</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-macro-can-not-return-to-the-variable-defined/m-p/377214#M276383</link>
      <description>&lt;P&gt;Hello Tom, sorry to reply you late.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried your codes, which works very well in this form&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let datevar=date ;
%let mois=put(&amp;amp;datevar,yymmn4.);
data want ;
  set have ;
  length newvar $4 ;
  newvar = &amp;amp;mois ;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when I want to concatenate with other string, it didn't work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date_deb = Date;
%let date_fin = intnx("month",&amp;amp;date_deb,+1,"sameday");
%let mois=put(&amp;amp;date_deb,yymmn4.);


DATA test;
SET save.list_id;
datedeb = &amp;amp;date_deb;
datefin = &amp;amp;date_fin;
month = "iMainBoutique&amp;amp;MOIS.Id";
segment = "iSegment2010_&amp;amp;MOIS.";
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And the results are:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Shop&lt;/TD&gt;&lt;TD&gt;Client&lt;/TD&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;Month&lt;/TD&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;datedeb&lt;/TD&gt;&lt;TD&gt;datefin&lt;/TD&gt;&lt;TD&gt;segment&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;BERLIN&lt;/TD&gt;&lt;TD&gt;Client1&lt;/TD&gt;&lt;TD&gt;01MAY2017&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;4890&lt;/TD&gt;&lt;TD&gt;20940&lt;/TD&gt;&lt;TD&gt;20971&lt;/TD&gt;&lt;TD&gt;iSegment2010_put(Date,yymmn4.)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;MILAN FEMME&lt;/TD&gt;&lt;TD&gt;Client2&lt;/TD&gt;&lt;TD&gt;01MAY2017&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;77314&lt;/TD&gt;&lt;TD&gt;20940&lt;/TD&gt;&lt;TD&gt;20971&lt;/TD&gt;&lt;TD&gt;iSegment2010_put(Date,yymmn4.)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;LONDON SELFRIDGES WOMAN&lt;/TD&gt;&lt;TD&gt;Client3&lt;/TD&gt;&lt;TD&gt;01MAY2017&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;186475&lt;/TD&gt;&lt;TD&gt;20940&lt;/TD&gt;&lt;TD&gt;20971&lt;/TD&gt;&lt;TD&gt;iSegment2010_put(Date,yymmn4.)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;PARIS MONTAIGNE&lt;/TD&gt;&lt;TD&gt;Client4&lt;/TD&gt;&lt;TD&gt;01MAY2017&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;424636&lt;/TD&gt;&lt;TD&gt;20940&lt;/TD&gt;&lt;TD&gt;20971&lt;/TD&gt;&lt;TD&gt;iSegment2010_put(Date,yymmn4.)&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;The variable month and segment is not correct. (the output of month and segment wanted are "iMainBoutique1705Id" and "iSegment2010_1705", which are the name of the variables in other tables)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And the log are as following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;23         DATA test;
24         SET save.list_id;
25         datedeb = &amp;amp;date_deb;
SYMBOLGEN:  Macro variable DATE_DEB resolves to Date
26         datefin = &amp;amp;date_fin;
SYMBOLGEN:  Macro variable DATE_FIN resolves to intnx("month",Date,+1,"sameday")
27         month = "iMainBoutique&amp;amp;MOIS.Id";
SYMBOLGEN:  Macro variable MOIS resolves to put(Date,yymmn4.)
28         segment = "iSegment2010_&amp;amp;MOIS.";
SYMBOLGEN:  Macro variable MOIS resolves to put(Date,yymmn4.)
29         RUN;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
      27:2   
NOTE: Invalid numeric data, 'iMainBoutiqueput(Date,yymmn4.)Id' , at line 27 column 2.
Boutique=BERLIN Client=Client1 Date=01MAY2017 Month=. ID=4890 datedeb=20940 datefin=20971
segment=iSegment2010_put(Date,yymmn4.) _ERROR_=1 _N_=1
NOTE: Invalid numeric data, 'iMainBoutiqueput(Date,yymmn4.)Id' , at line 27 column 2.
Boutique=MILAN FEMME Client=Client2 Date=01MAY2017 Month=. ID=77314 datedeb=20940 datefin=20971
segment=iSegment2010_put(Date,yymmn4.) _ERROR_=1 _N_=2
NOTE: Invalid numeric data, 'iMainBoutiqueput(Date,yymmn4.)Id' , at line 27 column 2.
Boutique=LONDON SELFRIDGES WOMAN Client=Client3 Date=01MAY2017 Month=. ID=186475 datedeb=20940 datefin=20971
segment=iSegment2010_put(Date,yymmn4.) _ERROR_=1 _N_=3
NOTE: Invalid numeric data, 'iMainBoutiqueput(Date,yymmn4.)Id' , at line 27 column 2.
Boutique=PARIS MONTAIGNE Client=Client4 Date=01MAY2017 Month=. ID=424636 datedeb=20940 datefin=20971
segment=iSegment2010_put(Date,yymmn4.) _ERROR_=1 _N_=4&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2017 09:17:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-macro-can-not-return-to-the-variable-defined/m-p/377214#M276383</guid>
      <dc:creator>viviwu</dc:creator>
      <dc:date>2017-07-19T09:17:07Z</dc:date>
    </item>
    <item>
      <title>Re: CALL SYMPUT macro, can not return to the variable defined</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-macro-can-not-return-to-the-variable-defined/m-p/377250#M276384</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA test;
SET save.list_id;
datedeb = &amp;amp;date_deb;
datefin = &amp;amp;date_fin;
month = cats("iMainBoutique", &amp;amp;MOIS, "Id");
segment = cats("iSegment2010_", &amp;amp;MOIS);
RUN&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested, &amp;amp;mois contains a datastep function, so do don't enclose it in quotes.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2017 11:12:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-macro-can-not-return-to-the-variable-defined/m-p/377250#M276384</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2017-07-19T11:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: CALL SYMPUT macro, can not return to the variable defined</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-macro-can-not-return-to-the-variable-defined/m-p/377270#M276385</link>
      <description>&lt;P&gt;Hello Andreas, thank you for your reply. It works well in the way in the example. But when I put into the original code, it still didn't work. I'm sorry that I should have provided the original code at the beginning instead of creating a example code. Here is the original code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let date_deb = Date;
%let date_fin = intnx("month",&amp;amp;date_deb,+1,"sameday");
%let mois=put(&amp;amp;date_deb,yymmn4.);

PROC SQL;
CREATE TABLE Client_base AS 

SELECT
DISTINCT R0.ID
,B3.sDivision as Zone&lt;BR /&gt;,P2.ProductCategory as Category&lt;BR /&gt;,sum(S2.iQuantity) as Quantity&lt;BR /&gt;,sum(S2.fTotalPrice) as Turnover

FROM  save.list_id R0
INNER JOIN VALIBLA2.VA_NmsRecipient R1			ON      (R0.ID = R1.iRecipientId)
INNER JOIN VALIBLA2.VA_ClientSegmentChina R2		ON	(R0.ID = R2.iRecipientId)

INNER JOIN VALIBLA2.VA_MAINBOUTIQUE1YARCHIVES B2	ON	(B2.iRecipientId = R1.iRecipientId)
INNER JOIN VALIBLA2.VA_Boutique B3 			ON	(B2.iMainBoutique&amp;amp;MOIS.Id = B3.iBoutiqueId)

LEFT JOIN VALIBLA2.va_sale S1				ON	(R1.iRecipientId = S1.iSaleRecipientId AND &amp;amp;date_deb. &amp;lt;= datepart(S1.tsDate) &amp;lt;= &amp;amp;date_fin.)

WHERE R1.iLinked = 1
GROUP BY 1,3,2;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;where the following code never work:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;INNER JOIN VALIBLA2.VA_Boutique B3 			ON	(B2.iMainBoutique&amp;amp;MOIS.Id = B3.iBoutiqueId)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And the log&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SYMBOLGEN:  Macro variable MOIS resolves to put(Date,yymmn4.)
ERROR 22-322: Syntax error, expecting one of the following: IN, NOTIN.  

ERROR 76-322: Syntax error, statement will be ignored.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Jul 2017 12:19:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-macro-can-not-return-to-the-variable-defined/m-p/377270#M276385</guid>
      <dc:creator>viviwu</dc:creator>
      <dc:date>2017-07-19T12:19:48Z</dc:date>
    </item>
    <item>
      <title>Re: CALL SYMPUT macro, can not return to the variable defined</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-macro-can-not-return-to-the-variable-defined/m-p/377286#M276386</link>
      <description>&lt;P&gt;Of course it does not work when used that way. &amp;nbsp;Just replace the macro variable reference &amp;amp;MOIS with the text that the macro variable has been defined to have. &amp;nbsp; And you get this&amp;nbsp;as the generated SAS code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;B2.iMainBoutiqueput(Date,yymmn4.)Id = B3.iBoutiqueId&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Variable names cannot contain characters like (.) &amp;nbsp;so that should generate SAS error messages.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks like you are trying to use a different VARIABLE NAME in your query for each observation. &amp;nbsp;SAS cannot do that.&lt;/P&gt;
&lt;P&gt;If you are running this as SQL code the way to make decisions based on the data is to use CASE statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case 
when (put(Date,yymmn4.) = '1601') then B2.iMainBoutique1601Id 
when (put(Date,yymmn4.) = '1602') then B2.iMainBoutique1602Id 
end= B3.iBoutiqueId&lt;/CODE&gt;&lt;/PRE&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;</description>
      <pubDate>Wed, 19 Jul 2017 12:39:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-macro-can-not-return-to-the-variable-defined/m-p/377286#M276386</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-07-19T12:39:57Z</dc:date>
    </item>
    <item>
      <title>Re: CALL SYMPUT macro, can not return to the variable defined</title>
      <link>https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-macro-can-not-return-to-the-variable-defined/m-p/377302#M276387</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;It looks like you are trying to use a different VARIABLE NAME in your query for each observation. &amp;nbsp;SAS cannot do that.&lt;/SPAN&gt;"&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OK, at least I know that it is not possible in SAS &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; Thank you for your kind help Tom.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Good day,&lt;/P&gt;&lt;P&gt;Vivian&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jul 2017 13:04:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/CALL-SYMPUT-macro-can-not-return-to-the-variable-defined/m-p/377302#M276387</guid>
      <dc:creator>viviwu</dc:creator>
      <dc:date>2017-07-19T13:04:16Z</dc:date>
    </item>
  </channel>
</rss>

