<?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 create a macro variable YYYYMM from MACRO varaibles YYYY and MM in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro-variable-YYYYMM-from-MACRO-varaibles-YYYY-and-MM/m-p/775556#M246529</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to create a macro variable YYYYMM that is created by concatenation of&amp;nbsp; MACRO varaibles YYYY and MM.&lt;/P&gt;
&lt;P&gt;When MM=09 and YYYY=2021 I expect to get 202109&amp;nbsp; but I get 20219 in way2 and way3.&lt;/P&gt;
&lt;P&gt;Why way2 and way3 are not working as I desired?&lt;/P&gt;
&lt;P&gt;What is the solution to adjust way2 and way3 to the desired outcome 202109?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let MM=09;
%put &amp;amp;MM; /*09*/
%let YYYY=2021;
%put &amp;amp;YYYY; /*2021*/
/**Way1**/
Data _null_;
sas_date=MDY(&amp;amp;MM.,1,&amp;amp;YYYY.);
YYYYMM=put(sas_date,YYMMn6.);
call symput('YYYYMM',YYYYMM);
Run;
%put &amp;amp;YYYYMM.;
/**Way2-no good because get 20219**/
%let YYYYMM= %sysfunc(catS(&amp;amp;YYYY.,&amp;amp;MM.));
%put &amp;amp;YYYYMM.;
/**Way3-no good because get 20219**/
data _null_;
call symput('YYYYMM2',catS(&amp;amp;YYYY.,&amp;amp;MM.));
run;
%put &amp;amp;YYYYMM.;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas" style="font-size: 16px; white-space: normal; background-color: #ffffff;"&gt; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 21 Oct 2021 05:08:52 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2021-10-21T05:08:52Z</dc:date>
    <item>
      <title>create a macro variable YYYYMM from MACRO varaibles YYYY and MM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro-variable-YYYYMM-from-MACRO-varaibles-YYYY-and-MM/m-p/775556#M246529</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to create a macro variable YYYYMM that is created by concatenation of&amp;nbsp; MACRO varaibles YYYY and MM.&lt;/P&gt;
&lt;P&gt;When MM=09 and YYYY=2021 I expect to get 202109&amp;nbsp; but I get 20219 in way2 and way3.&lt;/P&gt;
&lt;P&gt;Why way2 and way3 are not working as I desired?&lt;/P&gt;
&lt;P&gt;What is the solution to adjust way2 and way3 to the desired outcome 202109?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let MM=09;
%put &amp;amp;MM; /*09*/
%let YYYY=2021;
%put &amp;amp;YYYY; /*2021*/
/**Way1**/
Data _null_;
sas_date=MDY(&amp;amp;MM.,1,&amp;amp;YYYY.);
YYYYMM=put(sas_date,YYMMn6.);
call symput('YYYYMM',YYYYMM);
Run;
%put &amp;amp;YYYYMM.;
/**Way2-no good because get 20219**/
%let YYYYMM= %sysfunc(catS(&amp;amp;YYYY.,&amp;amp;MM.));
%put &amp;amp;YYYYMM.;
/**Way3-no good because get 20219**/
data _null_;
call symput('YYYYMM2',catS(&amp;amp;YYYY.,&amp;amp;MM.));
run;
%put &amp;amp;YYYYMM.;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas" style="font-size: 16px; white-space: normal; background-color: #ffffff;"&gt; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Oct 2021 05:08:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro-variable-YYYYMM-from-MACRO-varaibles-YYYY-and-MM/m-p/775556#M246529</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-10-21T05:08:52Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro variable YYYYMM from MACRO varaibles YYYY and MM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro-variable-YYYYMM-from-MACRO-varaibles-YYYY-and-MM/m-p/775557#M246530</link>
      <description>&lt;P&gt;try this&lt;BR /&gt;&lt;BR /&gt;call symput('YYYYMM',catS("&amp;amp;YYYY.","&amp;amp;MM."));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let YYYYMM= %sysfunc(catS(&amp;amp;YYYY.&amp;amp;MM.));&lt;/P&gt;</description>
      <pubDate>Thu, 21 Oct 2021 05:06:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro-variable-YYYYMM-from-MACRO-varaibles-YYYY-and-MM/m-p/775557#M246530</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-10-21T05:06:46Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro variable YYYYMM from MACRO varaibles YYYY and MM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro-variable-YYYYMM-from-MACRO-varaibles-YYYY-and-MM/m-p/775558#M246531</link>
      <description>&lt;P&gt;Working as expectable: The arguments of cats are treated as numerics, so leading zeros are stripped. You should drop %sysfunc from your syntax and just use:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let yyyymm = &amp;amp;yyyy.&amp;amp;mm.;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Oct 2021 05:05:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro-variable-YYYYMM-from-MACRO-varaibles-YYYY-and-MM/m-p/775558#M246531</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-10-21T05:05:29Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro variable YYYYMM from MACRO varaibles YYYY and MM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro-variable-YYYYMM-from-MACRO-varaibles-YYYY-and-MM/m-p/775560#M246533</link>
      <description>&lt;P&gt;What is the reason for difference between these 2 ways?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let YYYY=2021;
%let MM=09;
/***Way A***/
data _null_;
call symput('YYYYMM',catS("&amp;amp;YYYY.","&amp;amp;MM."));
run;
%put &amp;amp;YYYYMM.;/*Get 202109*/


/***Way B***/
%let YYYYMM= %sysfunc(catS("&amp;amp;YYYY.","&amp;amp;MM."));
%put &amp;amp;YYYYMM.;/*Get "2021""09"*/&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Oct 2021 05:36:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro-variable-YYYYMM-from-MACRO-varaibles-YYYY-and-MM/m-p/775560#M246533</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-10-21T05:36:08Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro variable YYYYMM from MACRO varaibles YYYY and MM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro-variable-YYYYMM-from-MACRO-varaibles-YYYY-and-MM/m-p/775563#M246535</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;What is the reason for difference between these 2 ways?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let YYYY=2021;
%let MM=09;
/***Way A***/
data _null_;
call symput('YYYYMM',catS("&amp;amp;YYYY.","&amp;amp;MM."));
run;
%put &amp;amp;YYYYMM.;/*Get 202109*/


/***Way B***/
%let YYYYMM= %sysfunc(catS("&amp;amp;YYYY.","&amp;amp;MM."));
%put &amp;amp;YYYYMM.;/*Get "2021""09"*/&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Because quotes are not necessary in the macro-world of sas, they are not treated as chars identifying a string, but as content of the variable.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Oct 2021 05:43:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro-variable-YYYYMM-from-MACRO-varaibles-YYYY-and-MM/m-p/775563#M246535</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-10-21T05:43:01Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro variable YYYYMM from MACRO varaibles YYYY and MM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro-variable-YYYYMM-from-MACRO-varaibles-YYYY-and-MM/m-p/775575#M246543</link>
      <description>&lt;P&gt;You overcomplicate things by a mile. In macro language, concatenation of texts is done in a simple %LET:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let yyyymm = &amp;amp;yyyy.&amp;amp;mm.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;A data step is only needed if you need to set macro variables from dataset values, or want to simplify calculations and avoid %SYSFUNC-avalanches.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Oct 2021 07:12:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro-variable-YYYYMM-from-MACRO-varaibles-YYYY-and-MM/m-p/775575#M246543</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-21T07:12:47Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro variable YYYYMM from MACRO varaibles YYYY and MM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro-variable-YYYYMM-from-MACRO-varaibles-YYYY-and-MM/m-p/775576#M246544</link>
      <description>&lt;P&gt;The macro processor is a &lt;U&gt;&lt;EM&gt;text&lt;/EM&gt;&lt;/U&gt; processor and does not need quotes to identify text as such. Quotes are part of text for the macro processor.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Write the above down repeatedly until you run out of paper or have finally internalized it.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Oct 2021 07:15:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro-variable-YYYYMM-from-MACRO-varaibles-YYYY-and-MM/m-p/775576#M246544</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-10-21T07:15:36Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro variable YYYYMM from MACRO varaibles YYYY and MM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro-variable-YYYYMM-from-MACRO-varaibles-YYYY-and-MM/m-p/775607#M246555</link>
      <description>&lt;P&gt;If it was up to me, I would change the correct answer to the one provided by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;, as %SYSFUNC(CATS()) is not needed to concatenate macro variables (which is a good lesson to learn).&lt;/P&gt;</description>
      <pubDate>Thu, 21 Oct 2021 11:33:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro-variable-YYYYMM-from-MACRO-varaibles-YYYY-and-MM/m-p/775607#M246555</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-21T11:33:59Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro variable YYYYMM from MACRO varaibles YYYY and MM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro-variable-YYYYMM-from-MACRO-varaibles-YYYY-and-MM/m-p/775648#M246570</link>
      <description>&lt;P&gt;The %SYSFUNC(CATS()) is doing nothing in that statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once the macro variables are resolved you already have the string.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let YYYYMM= &amp;amp;YYYY.&amp;amp;MM.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or in data step&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;yyyymm_var = "&amp;amp;yyyy.&amp;amp;mm.";&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Oct 2021 13:42:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro-variable-YYYYMM-from-MACRO-varaibles-YYYY-and-MM/m-p/775648#M246570</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-10-21T13:42:02Z</dc:date>
    </item>
    <item>
      <title>Re: create a macro variable YYYYMM from MACRO varaibles YYYY and MM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-a-macro-variable-YYYYMM-from-MACRO-varaibles-YYYY-and-MM/m-p/775660#M246572</link>
      <description>&lt;P&gt;I am curious as to why a problem would begin with have macro variables &amp;amp;YYYY and &amp;amp;MM, as opposed to starting with an actual date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you start with an actual date, you don't have to pull out the year into &amp;amp;YYYY and then pull out the month into &amp;amp;MM and then combine them. If you start with a date, then creating a macro variable &amp;amp;YYYYMM is trivial using formats.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems as if the problem starts at the wrong point, and if you just go back a little further to start with a date, there is no need to do the work to separate the year from the month and then re-combine them.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Oct 2021 14:34:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-a-macro-variable-YYYYMM-from-MACRO-varaibles-YYYY-and-MM/m-p/775660#M246572</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-21T14:34:55Z</dc:date>
    </item>
  </channel>
</rss>

