<?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: Generate-dynamic-picklist-of-months-and-years Part 2 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Generate-dynamic-picklist-of-months-and-years-Part-2/m-p/983045#M379445</link>
    <description>&lt;P&gt;Thanks.&amp;nbsp; Actually, that did not work.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;2183  /*51*/
2184
2185  data _null_;
2186  set months;
2187  n+1;
2188  call symputx(compress("year" || n), year);
2189  call symputx(compress("month" || n), put(month,z2.));
2190  run;

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      2188:33   2189:34
ERROR: Symbolic variable name YEAR-1 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('year-1',2024) at line 2188 column 6 is invalid.
ERROR: Symbolic variable name MONTH-1 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('month-1','12') at line 2189 column 6 is invalid.
date=202502 n=-1 year=2024 month=12 _ERROR_=1 _N_=3
ERROR: Symbolic variable name YEAR-2 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('year-2',2024) at line 2188 column 6 is invalid.
ERROR: Symbolic variable name MONTH-2 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('month-2','11') at line 2189 column 6 is invalid.
date=202502 n=-2 year=2024 month=11 _ERROR_=1 _N_=4
ERROR: Symbolic variable name YEAR-3 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('year-3',2024) at line 2188 column 6 is invalid.
ERROR: Symbolic variable name MONTH-3 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('month-3','10') at line 2189 column 6 is invalid.
date=202502 n=-3 year=2024 month=10 _ERROR_=1 _N_=5
ERROR: Symbolic variable name YEAR-4 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('year-4',2024) at line 2188 column 6 is invalid.
ERROR: Symbolic variable name MONTH-4 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('month-4','09') at line 2189 column 6 is invalid.
date=202502 n=-4 year=2024 month=9 _ERROR_=1 _N_=6
ERROR: Symbolic variable name YEAR-5 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('year-5',2024) at line 2188 column 6 is invalid.
ERROR: Symbolic variable name MONTH-5 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('month-5','08') at line 2189 column 6 is invalid.
date=202502 n=-5 year=2024 month=8 _ERROR_=1 _N_=7
ERROR: Symbolic variable name YEAR-6 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('year-6',2024) at line 2188 column 6 is invalid.
ERROR: Symbolic variable name MONTH-6 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('month-6','07') at line 2189 column 6 is invalid.
date=202502 n=-6 year=2024 month=7 _ERROR_=1 _N_=8
ERROR: Symbolic variable name YEAR-7 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('year-7',2024) at line 2188 column 6 is invalid.
ERROR: Symbolic variable name MONTH-7 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('month-7','06') at line 2189 column 6 is invalid.
date=202502 n=-7 year=2024 month=6 _ERROR_=1 _N_=9
ERROR: Symbolic variable name YEAR-8 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('year-8',2024) at line 2188 column 6 is invalid.
ERROR: Symbolic variable name MONTH-8 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('month-8','05') at line 2189 column 6 is invalid.
date=202502 n=-8 year=2024 month=5 _ERROR_=1 _N_=10
ERROR: Symbolic variable name YEAR-9 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('year-9',2024) at line 2188 column 6 is invalid.
ERROR: Symbolic variable name MONTH-9 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('month-9','04') at line 2189 column 6 is invalid.
date=202502 n=-9 year=2024 month=4 _ERROR_=1 _N_=11
ERROR: Symbolic variable name YEAR-10 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('year-10',2024) at line 2188 column 6 is invalid.
ERROR: Symbolic variable name MONTH-10 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('month-10','03') at line 2189 column 6 is invalid.
date=202502 n=-10 year=2024 month=3 _ERROR_=1 _N_=12
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 12 observations read from the data set WORK.MONTHS.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But this did:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table distinct_months as
select distinct year , put(month,z2.) as month
from months
order by year , month ;
quit ; 

proc sql noprint;
select year, month
into :year1 - :year12, :month1 - :month12
from distinct_months;
quit;

%put &amp;amp;=year1 &amp;amp;=month1; 
%put &amp;amp;=year2 &amp;amp;=month2; 
%put &amp;amp;=year3 &amp;amp;=month3; 
%put &amp;amp;=year4 &amp;amp;=month4; 
%put &amp;amp;=year5 &amp;amp;=month5; 
%put &amp;amp;=year6 &amp;amp;=month6; 
%put &amp;amp;=year7 &amp;amp;=month7; 
%put &amp;amp;=year8 &amp;amp;=month8; 
%put &amp;amp;=year9 &amp;amp;=month9; 
%put &amp;amp;=year10 &amp;amp;=month10;
%put &amp;amp;=year11 &amp;amp;=month11;
%put &amp;amp;=year12 &amp;amp;=month12;&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 04 Feb 2026 20:15:48 GMT</pubDate>
    <dc:creator>texasmfp</dc:creator>
    <dc:date>2026-02-04T20:15:48Z</dc:date>
    <item>
      <title>Generate-dynamic-picklist-of-months-and-years Part 2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-dynamic-picklist-of-months-and-years-Part-2/m-p/982980#M379428</link>
      <description>&lt;P&gt;This is a follow-up to this thread:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Generate-dynamic-picklist-of-months-and-years/m-p/982909#M379413" target="_blank"&gt;Solved: Re: Generate dynamic picklist of months and years - SAS Support Communities&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Again, thanks to Ksharp.&amp;nbsp; The following code generates a table of years and months for the 12 preceding months from a defined date:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let rmonth = 02;
%let ryear = 2025;
&lt;BR /&gt;* Assure that RMONTH is zero-filled (eg, 03 not 3) ;&lt;BR /&gt;/*30*/ %let rmonth = %sysfunc(putn(&amp;amp;rmonth,z2.) ) ;&lt;BR /&gt;
data months ;
date=input("&amp;amp;ryear.&amp;amp;rmonth.",yymmn6.);
format date yymmn6.;
do n=0 to -11 by -1;
  year=year(intnx('month',date,n));
  month=month(intnx('month',date,n));
  output;
end;
run;

proc sql ;
create table distinct_months as
select distinct year , month
	  from months
	 order by year , month ;
quit ; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The table is:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;year	month
2024	3
2024	4
2024	5
2024	6
2024	7
2024	8
2024	9
2024	10
2024	11
2024	12
2025	1
2025	2
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I realized that I also need to put each of these year/month values into macro variables so that I can call them at various points later in the program.&amp;nbsp; Moreover, if the month value is 1-9 (i.e., January through September), it needs a 0 backfill in front of the value.&amp;nbsp; Ultimately, I need to dynamically generate something like this, again using the rmonth=02 and ryear=2025 starting date above:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%Let year1=2024;
%Let month1=03;
%Let year2=2024;
%Let month2=04;
%Let year3=2024;
%Let month3=05;
%Let year4=2024;
%Let month4=06;
%Let year5=2024;
%Let month5=07;
%Let year6=2024;
%Let month6=08;
%Let year7=2024;
%Let month7=09;
%Let year8=2024;
%Let month8=10;
%Let year9=2024;
%Let month9=11;
%Let year10=2024;
%Let month10=12;
%Let year11=2025;
%Let month11=01;
%Let year12=2025;
%Let month12=02;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 03 Feb 2026 21:54:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-dynamic-picklist-of-months-and-years-Part-2/m-p/982980#M379428</guid>
      <dc:creator>texasmfp</dc:creator>
      <dc:date>2026-02-03T21:54:23Z</dc:date>
    </item>
    <item>
      <title>Re: Generate-dynamic-picklist-of-months-and-years Part 2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-dynamic-picklist-of-months-and-years-Part-2/m-p/982990#M379429</link>
      <description>&lt;P&gt;You could just do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set months;
n+1;
call symputx(compress("year" || n), year);
call symputx(compress("month" || n), put(month,z2.));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Feb 2026 02:19:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-dynamic-picklist-of-months-and-years-Part-2/m-p/982990#M379429</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2026-02-04T02:19:47Z</dc:date>
    </item>
    <item>
      <title>Re: Generate-dynamic-picklist-of-months-and-years Part 2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-dynamic-picklist-of-months-and-years-Part-2/m-p/983045#M379445</link>
      <description>&lt;P&gt;Thanks.&amp;nbsp; Actually, that did not work.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;2183  /*51*/
2184
2185  data _null_;
2186  set months;
2187  n+1;
2188  call symputx(compress("year" || n), year);
2189  call symputx(compress("month" || n), put(month,z2.));
2190  run;

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      2188:33   2189:34
ERROR: Symbolic variable name YEAR-1 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('year-1',2024) at line 2188 column 6 is invalid.
ERROR: Symbolic variable name MONTH-1 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('month-1','12') at line 2189 column 6 is invalid.
date=202502 n=-1 year=2024 month=12 _ERROR_=1 _N_=3
ERROR: Symbolic variable name YEAR-2 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('year-2',2024) at line 2188 column 6 is invalid.
ERROR: Symbolic variable name MONTH-2 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('month-2','11') at line 2189 column 6 is invalid.
date=202502 n=-2 year=2024 month=11 _ERROR_=1 _N_=4
ERROR: Symbolic variable name YEAR-3 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('year-3',2024) at line 2188 column 6 is invalid.
ERROR: Symbolic variable name MONTH-3 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('month-3','10') at line 2189 column 6 is invalid.
date=202502 n=-3 year=2024 month=10 _ERROR_=1 _N_=5
ERROR: Symbolic variable name YEAR-4 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('year-4',2024) at line 2188 column 6 is invalid.
ERROR: Symbolic variable name MONTH-4 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('month-4','09') at line 2189 column 6 is invalid.
date=202502 n=-4 year=2024 month=9 _ERROR_=1 _N_=6
ERROR: Symbolic variable name YEAR-5 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('year-5',2024) at line 2188 column 6 is invalid.
ERROR: Symbolic variable name MONTH-5 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('month-5','08') at line 2189 column 6 is invalid.
date=202502 n=-5 year=2024 month=8 _ERROR_=1 _N_=7
ERROR: Symbolic variable name YEAR-6 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('year-6',2024) at line 2188 column 6 is invalid.
ERROR: Symbolic variable name MONTH-6 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('month-6','07') at line 2189 column 6 is invalid.
date=202502 n=-6 year=2024 month=7 _ERROR_=1 _N_=8
ERROR: Symbolic variable name YEAR-7 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('year-7',2024) at line 2188 column 6 is invalid.
ERROR: Symbolic variable name MONTH-7 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('month-7','06') at line 2189 column 6 is invalid.
date=202502 n=-7 year=2024 month=6 _ERROR_=1 _N_=9
ERROR: Symbolic variable name YEAR-8 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('year-8',2024) at line 2188 column 6 is invalid.
ERROR: Symbolic variable name MONTH-8 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('month-8','05') at line 2189 column 6 is invalid.
date=202502 n=-8 year=2024 month=5 _ERROR_=1 _N_=10
ERROR: Symbolic variable name YEAR-9 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('year-9',2024) at line 2188 column 6 is invalid.
ERROR: Symbolic variable name MONTH-9 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('month-9','04') at line 2189 column 6 is invalid.
date=202502 n=-9 year=2024 month=4 _ERROR_=1 _N_=11
ERROR: Symbolic variable name YEAR-10 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('year-10',2024) at line 2188 column 6 is invalid.
ERROR: Symbolic variable name MONTH-10 must contain only letters, digits, and underscores.
NOTE: Argument 1 to function SYMPUTX('month-10','03') at line 2189 column 6 is invalid.
date=202502 n=-10 year=2024 month=3 _ERROR_=1 _N_=12
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 12 observations read from the data set WORK.MONTHS.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But this did:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table distinct_months as
select distinct year , put(month,z2.) as month
from months
order by year , month ;
quit ; 

proc sql noprint;
select year, month
into :year1 - :year12, :month1 - :month12
from distinct_months;
quit;

%put &amp;amp;=year1 &amp;amp;=month1; 
%put &amp;amp;=year2 &amp;amp;=month2; 
%put &amp;amp;=year3 &amp;amp;=month3; 
%put &amp;amp;=year4 &amp;amp;=month4; 
%put &amp;amp;=year5 &amp;amp;=month5; 
%put &amp;amp;=year6 &amp;amp;=month6; 
%put &amp;amp;=year7 &amp;amp;=month7; 
%put &amp;amp;=year8 &amp;amp;=month8; 
%put &amp;amp;=year9 &amp;amp;=month9; 
%put &amp;amp;=year10 &amp;amp;=month10;
%put &amp;amp;=year11 &amp;amp;=month11;
%put &amp;amp;=year12 &amp;amp;=month12;&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Feb 2026 20:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-dynamic-picklist-of-months-and-years-Part-2/m-p/983045#M379445</guid>
      <dc:creator>texasmfp</dc:creator>
      <dc:date>2026-02-04T20:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: Generate-dynamic-picklist-of-months-and-years Part 2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-dynamic-picklist-of-months-and-years-Part-2/m-p/983047#M379446</link>
      <description>&lt;P&gt;The data step will work fine if you give it the same input, DISTINCT_MONTHS, as you gave the SQL query.&lt;/P&gt;
&lt;P&gt;But you should not need to use the COMPRESS() function.&amp;nbsp; Just use the CATS() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set distinct_months;
  n+1;
  call symputx(cats("year",n), year);
  call symputx(cats("month",n), month);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the goal is just to make the macro variables then skip making the dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select distinct year, put(month,z2.)
  into :year1- , :month1-
  from months
  order by year , month 
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Feb 2026 20:25:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-dynamic-picklist-of-months-and-years-Part-2/m-p/983047#M379446</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-02-04T20:25:33Z</dc:date>
    </item>
    <item>
      <title>Re: Generate-dynamic-picklist-of-months-and-years Part 2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-dynamic-picklist-of-months-and-years-Part-2/m-p/983058#M379447</link>
      <description>&lt;P&gt;To get those error messages the dataset MONTH must have already had a variable named N.&lt;/P&gt;
&lt;P&gt;If that is the case then the SUM statement will just increment the value of N read from the source dataset by one.&amp;nbsp; So an existing value of -2 would be transformed to -1 and yield a variable name of YEAR-1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Run this example to see:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data good(drop=n) bad;
  do n=-12 to 0 ;
     date = intnx('month',today(),n);
     year=year(date);
     month=month(date);
     output;
  end;
run;

data _null_;
  set good;
  n+1;
  call symputx(cats('year',n),year);
run;

data _null_;
  set bad;
  n+1;
  call symputx(cats('year',n),year);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Feb 2026 20:32:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-dynamic-picklist-of-months-and-years-Part-2/m-p/983058#M379447</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2026-02-04T20:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: Generate-dynamic-picklist-of-months-and-years Part 2</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-dynamic-picklist-of-months-and-years-Part-2/m-p/983059#M379448</link>
      <description>&lt;P&gt;Yes, the solution (from the other thread) created a months dataset with 4 variables, including n.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 04 Feb 2026 20:58:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-dynamic-picklist-of-months-and-years-Part-2/m-p/983059#M379448</guid>
      <dc:creator>texasmfp</dc:creator>
      <dc:date>2026-02-04T20:58:54Z</dc:date>
    </item>
  </channel>
</rss>

