<?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: Month list separated by ',' ( 'Jan','Feb','Mar',Apr','May.......,'Dec') in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Month-list-separated-by-Jan-Feb-Mar-Apr-May-Dec/m-p/645850#M193114</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/293911"&gt;@anjicamsas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Depending on the situation, you might want to&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;output a macrovariable: the solution provided by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;is the best way to achieve this using proc sql&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
	select quote(strip(Mon),"'")
	/* Put the list into a macrovariable*/
	into: list_month separated by ", "
	from Month;
quit;

%put &amp;amp;list_month.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;output a new variable in your dataset (+ optionally put the value into a macrovariable). in this case you can use the following approach:&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set month end=eof;
	length list_month $ 200;
	retain list_month;
	if _n_=1 then list_month = quote(strip(Mon),"'");
	else list_month = catx(", ", list_month, quote(strip(Mon),"'"));
	if eof then do;
		/* Put the list into a macrovariable*/
		call symputx("_list_month",list_month);
		/* Output the list in the dataset */
		output; 
	end;
	drop mon;
run;

%put &amp;amp;_list_month.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;By default, the QUOTE() function put double quotes. You can specify that you want single quote by adding a second argument: quote(your_variable,"&lt;FONT color="#FF00FF"&gt;'&lt;/FONT&gt;").&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 07 May 2020 13:38:45 GMT</pubDate>
    <dc:creator>ed_sas_member</dc:creator>
    <dc:date>2020-05-07T13:38:45Z</dc:date>
    <item>
      <title>Month list separated by ',' ( 'Jan','Feb','Mar',Apr','May.......,'Dec')</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-list-separated-by-Jan-Feb-Mar-Apr-May-Dec/m-p/645835#M193102</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have following dataset named Month with single variable Mon contains all the names of month.&lt;/P&gt;&lt;P&gt;I need output as follows&lt;/P&gt;&lt;P&gt;'Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'&lt;/P&gt;&lt;P&gt;(Each Month separated by ',' )&lt;/P&gt;&lt;P&gt;COULD YOU PLEASE HELP ME.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data Month;&lt;BR /&gt;input Mon $3.;&lt;BR /&gt;datalines;&lt;BR /&gt;Jan&lt;BR /&gt;Feb&lt;BR /&gt;Mar&lt;BR /&gt;Apr&lt;BR /&gt;May&lt;BR /&gt;Jun&lt;BR /&gt;Jul&lt;BR /&gt;Aug&lt;BR /&gt;Sep&lt;BR /&gt;Oct&lt;BR /&gt;Nov&lt;BR /&gt;Dec&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2020 12:09:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-list-separated-by-Jan-Feb-Mar-Apr-May-Dec/m-p/645835#M193102</guid>
      <dc:creator>anjicamsas</dc:creator>
      <dc:date>2020-05-07T12:09:07Z</dc:date>
    </item>
    <item>
      <title>Re: Month list separated by ',' ( 'Jan','Feb','Mar',Apr','May.......,'Dec')</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-list-separated-by-Jan-Feb-Mar-Apr-May-Dec/m-p/645843#M193109</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data Month;
input Mon $3.;
datalines;
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
Dec
;
run;

proc sql noprint;
select quote(mon) into : mons separated by ',' from month;
quit;

%put &amp;amp;mons ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 May 2020 12:10:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-list-separated-by-Jan-Feb-Mar-Apr-May-Dec/m-p/645843#M193109</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-05-07T12:10:53Z</dc:date>
    </item>
    <item>
      <title>Re: Month list separated by ',' ( 'Jan','Feb','Mar',Apr','May.......,'Dec')</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-list-separated-by-Jan-Feb-Mar-Apr-May-Dec/m-p/645850#M193114</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/293911"&gt;@anjicamsas&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Depending on the situation, you might want to&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;output a macrovariable: the solution provided by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;is the best way to achieve this using proc sql&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
	select quote(strip(Mon),"'")
	/* Put the list into a macrovariable*/
	into: list_month separated by ", "
	from Month;
quit;

%put &amp;amp;list_month.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;output a new variable in your dataset (+ optionally put the value into a macrovariable). in this case you can use the following approach:&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set month end=eof;
	length list_month $ 200;
	retain list_month;
	if _n_=1 then list_month = quote(strip(Mon),"'");
	else list_month = catx(", ", list_month, quote(strip(Mon),"'"));
	if eof then do;
		/* Put the list into a macrovariable*/
		call symputx("_list_month",list_month);
		/* Output the list in the dataset */
		output; 
	end;
	drop mon;
run;

%put &amp;amp;_list_month.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;By default, the QUOTE() function put double quotes. You can specify that you want single quote by adding a second argument: quote(your_variable,"&lt;FONT color="#FF00FF"&gt;'&lt;/FONT&gt;").&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2020 13:38:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-list-separated-by-Jan-Feb-Mar-Apr-May-Dec/m-p/645850#M193114</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-07T13:38:45Z</dc:date>
    </item>
    <item>
      <title>Re: Month list separated by ',' ( 'Jan','Feb','Mar',Apr','May.......,'Dec')</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-list-separated-by-Jan-Feb-Mar-Apr-May-Dec/m-p/645855#M193116</link>
      <description>&lt;P&gt;The core idea is to use CATX with a RETAINed variable in order to build up the list of quoted values.&amp;nbsp; I like to TRIM my values before quoting them so as to avoid trailing spaces in the quoted value.&amp;nbsp; In your case it does not matter because all the values are three characters long and the variable is $3.&amp;nbsp; A subsetting IF is used to trigger an implicit OUTPUT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want(keep=list);
  set month end=done;
  length list $100; 
  retain list '';
  list = catx(',', list, quote(trim(mon),"'"));
  if done;
run;

proc print data=want;
run;&lt;/PRE&gt;
&lt;P&gt;Output&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="RichardADeVenezia_0-1588856517565.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/39157i151A0A123BF206B3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="RichardADeVenezia_0-1588856517565.png" alt="RichardADeVenezia_0-1588856517565.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 May 2020 13:02:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-list-separated-by-Jan-Feb-Mar-Apr-May-Dec/m-p/645855#M193116</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-05-07T13:02:16Z</dc:date>
    </item>
    <item>
      <title>Re: Month list separated by ',' ( 'Jan','Feb','Mar',Apr','May.......,'Dec')</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-list-separated-by-Jan-Feb-Mar-Apr-May-Dec/m-p/645924#M193144</link>
      <description>&lt;P&gt;Two ways to accomplish this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use a data step and as you go through each line add the value to the list incrementally&lt;/P&gt;
&lt;P&gt;Transpose your data to a wide format and use the CATX() function on the resulting variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Both are illustrated below, with a case where you may need to do it by group.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*create sample data for demonstration;
data have;
    infile cards dlm='09'x;
    input OrgID Product $   States $;
    cards;
1   football    DC
1   football    VA
1   football    MD
2   football    CA
3   football    NV
3   football    CA
;
run;

*Sort - required for both options;
proc sort data=have;
    by orgID;
run;

**********************************************************************;
*Use RETAIN and BY group processing to combine the information;
**********************************************************************;
data want_option1;
    set have;
    by orgID;
    length combined $100.;
    retain combined;

    if first.orgID then
        combined=states;
    else
        combined=catx(', ', combined, states);

    if last.orgID then
        output;
run;

**********************************************************************;
*Transpose it to a wide format and then combine into a single field;
**********************************************************************;
proc transpose data=have out=wide prefix=state_;
    by orgID;
    var states;
run;

data want_option2;
    set wide;
    length combined $100.;
    combined=catx(', ', of state_:);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 May 2020 15:38:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-list-separated-by-Jan-Feb-Mar-Apr-May-Dec/m-p/645924#M193144</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-05-07T15:38:32Z</dc:date>
    </item>
    <item>
      <title>Re: Month list separated by ',' ( 'Jan','Feb','Mar',Apr','May.......,'Dec')</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-list-separated-by-Jan-Feb-Mar-Apr-May-Dec/m-p/645965#M193168</link>
      <description>&lt;P&gt;Here is another way, similar to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;transpose, but done in a single step.&amp;nbsp; I call the approach 'extrusion' because I envision pushing down the data set and the values get pushed to the right..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want(keep=list);
  set months end=done;
  array months(12) $5 _temporary_;
  months(_n_) = quote(mon,"'");
  if done;
  list = catx(',', of months(*));
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 May 2020 17:41:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-list-separated-by-Jan-Feb-Mar-Apr-May-Dec/m-p/645965#M193168</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-05-07T17:41:13Z</dc:date>
    </item>
  </channel>
</rss>

