<?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: how to created macro variable containing all values of the variable (no proc sql wanted) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/787949#M251845</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/411144"&gt;@abhinayingole&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;i believe sql will take it as alphabetically&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Test it. You might be surprised.&lt;/P&gt;</description>
    <pubDate>Fri, 31 Dec 2021 18:40:54 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-12-31T18:40:54Z</dc:date>
    <item>
      <title>how to created macro variable containing all values of the variable (no proc sql wanted)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/787940#M251838</link>
      <description>&lt;P&gt;below is the simple dataset.&lt;/P&gt;&lt;P&gt;I wanted to create macro variable, containing values of 'test' variable separated by space.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't want to use proc sql.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please suggest.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Expected output as ...&lt;/P&gt;&lt;P&gt;B A&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data test;
  test = "B"; output;
  test = "A"; output;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="abhinayingole_0-1640974371689.png" style="width: 107px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67061i0BB3E3BB5EABB048/image-dimensions/107x106?v=v2" width="107" height="106" role="button" title="abhinayingole_0-1640974371689.png" alt="abhinayingole_0-1640974371689.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Dec 2021 18:18:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/787940#M251838</guid>
      <dc:creator>abhinayingole</dc:creator>
      <dc:date>2021-12-31T18:18:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to created macro variable containing all values of the variable (no proc sql wanted)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/787941#M251839</link>
      <description>Why no SQL?&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 31 Dec 2021 18:23:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/787941#M251839</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-31T18:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: how to created macro variable containing all values of the variable (no proc sql wanted)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/787942#M251840</link>
      <description>i believe sql will take it as alphabetically</description>
      <pubDate>Fri, 31 Dec 2021 18:25:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/787942#M251840</guid>
      <dc:creator>abhinayingole</dc:creator>
      <dc:date>2021-12-31T18:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to created macro variable containing all values of the variable (no proc sql wanted)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/787943#M251841</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  test = "B"; output;
  test = "A"; output;
run;

data _null_;

set test end=eof;
length str $100.;

retain str;

str = catx(" ", str, test);

if eof then call symputx('no_sql_list', str);

run;


%put &amp;amp;no_sql_list;


proc sql noprint;
select test into :sql_list separated by " " from test;
quit;

%put &amp;amp;sql_list;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/411144"&gt;@abhinayingole&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;below is the simple dataset.&lt;/P&gt;
&lt;P&gt;I wanted to create macro variable, containing values of 'test' variable separated by space.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't want to use proc sql.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;please suggest.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Expected output as ...&lt;/P&gt;
&lt;P&gt;B A&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data test;
  test = "B"; output;
  test = "A"; output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="abhinayingole_0-1640974371689.png" style="width: 107px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67061i0BB3E3BB5EABB048/image-dimensions/107x106?v=v2" width="107" height="106" role="button" title="abhinayingole_0-1640974371689.png" alt="abhinayingole_0-1640974371689.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Dec 2021 18:26:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/787943#M251841</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-31T18:26:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to created macro variable containing all values of the variable (no proc sql wanted)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/787944#M251842</link>
      <description>&lt;P&gt;For anyone else reading along who doesn't have the "No SQL" restriction (which seems rather pointless to me as PROC SQL is part of Base SAS, so everyone has it)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
     select distinct(varname) into :macrovariablename separated by ' ' from datasetname;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What could be simpler?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And don't forget &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 14&lt;/A&gt;, Use the Right Tool&lt;/P&gt;</description>
      <pubDate>Fri, 31 Dec 2021 18:26:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/787944#M251842</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-31T18:26:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to created macro variable containing all values of the variable (no proc sql wanted)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/787945#M251843</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/411144"&gt;@abhinayingole&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;i believe sql will take it as alphabetically&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You can modify SQL so the values are in some non-alphabetic order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data seq;
    set test;
    n=_n_;
run;

proc sql noprint;
	select distinct test into :macrovar separated by ' ' from seq order by n;
quit;
%put &amp;amp;=macrovar;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 31 Dec 2021 18:30:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/787945#M251843</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-31T18:30:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to created macro variable containing all values of the variable (no proc sql wanted)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/787946#M251844</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/411144"&gt;@abhinayingole&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;i believe sql will take it as alphabetically&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Test your assumptions.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Dec 2021 18:28:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/787946#M251844</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-31T18:28:35Z</dc:date>
    </item>
    <item>
      <title>Re: how to created macro variable containing all values of the variable (no proc sql wanted)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/787949#M251845</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/411144"&gt;@abhinayingole&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;i believe sql will take it as alphabetically&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Test it. You might be surprised.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Dec 2021 18:40:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/787949#M251845</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-12-31T18:40:54Z</dc:date>
    </item>
    <item>
      <title>Re: how to created macro variable containing all values of the variable (no proc sql wanted)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/787966#M251851</link>
      <description>&lt;P&gt;There does seem to be a significant proportion of posters that demand a problem be done in a certain way regardless of whether it is the best approach or not.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All I can say to them is look at all of the options and choose the best. You won't improve your SAS skills if you keep insisting your problem has to be done a certain way.&lt;/P&gt;</description>
      <pubDate>Sat, 01 Jan 2022 01:28:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/787966#M251851</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-01-01T01:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: how to created macro variable containing all values of the variable (no proc sql wanted)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/787972#M251852</link>
      <description>The DISTINCT option forces SQL to alphabetize the values.  Just leave it out (assuming your data doesn't contain duplicated values).&lt;BR /&gt;&lt;BR /&gt;Better yet:  describe the next step(s) once you have your macro variable.  There are enough clever posters here that you may not need this macro variable at all.</description>
      <pubDate>Sat, 01 Jan 2022 07:24:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/787972#M251852</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2022-01-01T07:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: how to created macro variable containing all values of the variable (no proc sql wanted)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/788007#M251863</link>
      <description>&lt;P&gt;Agree with others, the SQL solution seems natural here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But just for fun,&amp;nbsp; I think the below DATA step will work too.&amp;nbsp; It will be slow, as it is over-writing the macro variable for every iteration of the step, vs&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;'s DATA step which (sensibly) only writes the macro variable once.&amp;nbsp; But if you're learning the macro language, it's a helpful example of the sort of timing issues you can encounter.&amp;nbsp; In this case, using the DATA step RESOLVE function allows you to resolve a macro variable during DATA step execution time rather than during DATA step compile time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  test = "B"; output;
  test = "A"; output;
run;

%let no_sql_list= ;

data _null_ ;
  set test ;
  call symputx('no_sql_list', catx(" ",resolve('&amp;amp;no_sql_list'),test)) ;
run ;

%put &amp;gt;&amp;gt;&amp;amp;no_sql_list&amp;lt;&amp;lt;;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 01 Jan 2022 22:14:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/788007#M251863</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-01-01T22:14:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to created macro variable containing all values of the variable (no proc sql wanted)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/788020#M251869</link>
      <description>&lt;P&gt;I might not be quite awake at the moment but macro variables do not per se create any output.&lt;/P&gt;
&lt;P&gt;You have to use some statement or procedure to create "output". Where it appears could make a significant difference. What does your intended output go into? A data set(other questions to be answered)? A text file (no macro variables needed but likely other questions will need answers)? Word document? PDF document? External database ? Something else?&lt;/P&gt;</description>
      <pubDate>Sun, 02 Jan 2022 07:54:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/788020#M251869</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-01-02T07:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: how to created macro variable containing all values of the variable (no proc sql wanted)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/788043#M251879</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  test = "B"; output;
  test = "A"; output;
run;
proc transpose data=test out=have;
	var test;
run;
data _NULL_;
  set have;
    call symputx('macvar', catx(' ',of col:));
run;
%put &amp;amp;=macvar;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ghosh_1-1641160317707.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67067i529840D3C3811C02/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ghosh_1-1641160317707.png" alt="ghosh_1-1641160317707.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 02 Jan 2022 21:52:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-created-macro-variable-containing-all-values-of-the/m-p/788043#M251879</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2022-01-02T21:52:13Z</dc:date>
    </item>
  </channel>
</rss>

