<?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: Quoted spaces at end of Macro variable list in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480905#M286684</link>
    <description>&lt;P&gt;You still only need one PROC SQL.&amp;nbsp; Multiple SELECT statements are allowed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's probably easiest and clearest to write a small macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro onelist (varname);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select quote(trim(&amp;amp;varname)) into :List_&amp;amp;varname separated by ' '&amp;nbsp; where &amp;amp;varname &amp;gt; ' '&amp;nbsp; from categories;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mend one_list;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can go with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;%onelist (house)&lt;/P&gt;
&lt;P&gt;%onelist (portfolio)&lt;/P&gt;
&lt;P&gt;%onelist (city)&lt;/P&gt;
&lt;P&gt;etc.&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Less typing, definitely less error-prone.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 24 Jul 2018 19:08:12 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-07-24T19:08:12Z</dc:date>
    <item>
      <title>Quoted spaces at end of Macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480879#M286673</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working with an excel document attached below: This&amp;nbsp;excel file is a categorical file that contains categorical variables which are not completely related. i.e. if you take a row and go across it from left to right, each new variable value is not related to the other. Data is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2018-07-24 at 19.56.50.png" style="width: 431px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21982i16FF747982A7F792/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2018-07-24 at 19.56.50.png" alt="Screen Shot 2018-07-24 at 19.56.50.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My objective is to store each of these categorical fields in a separate macro variable list. The codes i have written are:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc import datafile="/home/frupaul0/Carpenter/Demo1.xlsx" dbms=xlsx out=Categories;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;proc sql noprint;&lt;BR /&gt;select&lt;BR /&gt;quote(trim(House)),&lt;BR /&gt;Portfolio,&lt;BR /&gt;quote(trim(City))&lt;BR /&gt;into :List_house separated by '',&lt;BR /&gt;:List_portfolio separated by '',&lt;BR /&gt;:List_city separated by ''&lt;BR /&gt;from Categories;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;%put &amp;amp;List_city;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When the %put Statement is run, i notice some quoted spaces as shown blow:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2018-07-24 at 19.42.14.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21978iA07CDE60D8D19DE7/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2018-07-24 at 19.42.14.png" alt="Screen Shot 2018-07-24 at 19.42.14.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I get rid of those quoted blanks at the end please?&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 19:00:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480879#M286673</guid>
      <dc:creator>frupaul</dc:creator>
      <dc:date>2018-07-24T19:00:14Z</dc:date>
    </item>
    <item>
      <title>Re: Quoted spaces at end of Macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480882#M286674</link>
      <description>&lt;P&gt;Sorry I posted without asking my question. How can I get rid of those quoted blanks? Is there any function that can help me achieve this?&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 18:38:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480882#M286674</guid>
      <dc:creator>frupaul</dc:creator>
      <dc:date>2018-07-24T18:38:59Z</dc:date>
    </item>
    <item>
      <title>Re: Quoted spaces at end of Macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480883#M286675</link>
      <description>&lt;P&gt;you mean trailing blanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;use trim&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;quote(trim(House))&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 18:42:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480883#M286675</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-24T18:42:15Z</dc:date>
    </item>
    <item>
      <title>Re: Quoted spaces at end of Macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480885#M286676</link>
      <description>&lt;P&gt;Not really. I have just edited question because i realised i omitted the trim function. The problem is with the quoted blanks (as shown in the log) contained in the macro variable. Please refer to post&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 18:45:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480885#M286676</guid>
      <dc:creator>frupaul</dc:creator>
      <dc:date>2018-07-24T18:45:40Z</dc:date>
    </item>
    <item>
      <title>Re: Quoted spaces at end of Macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480886#M286677</link>
      <description>&lt;P&gt;missing values???&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;should add a condition to ignore missing values perhaps, like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and not missing(var);&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 18:46:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480886#M286677</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-24T18:46:09Z</dc:date>
    </item>
    <item>
      <title>Re: Quoted spaces at end of Macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480892#M286678</link>
      <description>&lt;P&gt;That would work if i were only creating one variable list. In this case i am creating three variable list. Using that condition will drop out values for the other categorical variables&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 18:53:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480892#M286678</guid>
      <dc:creator>frupaul</dc:creator>
      <dc:date>2018-07-24T18:53:59Z</dc:date>
    </item>
    <item>
      <title>Re: Quoted spaces at end of Macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480893#M286679</link>
      <description>&lt;P&gt;Can you please post a sample data with a few records of what you have and your requirement. So people can work with and offer you a solution&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 18:55:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480893#M286679</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-07-24T18:55:16Z</dc:date>
    </item>
    <item>
      <title>Re: Quoted spaces at end of Macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480897#M286680</link>
      <description>&lt;P&gt;Just adding in sample data as requested (excel file supporting this is&amp;nbsp;included in original post):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2018-07-24 at 19.56.50.png" style="width: 431px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21981iAAB095650A929823/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2018-07-24 at 19.56.50.png" alt="Screen Shot 2018-07-24 at 19.56.50.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 18:57:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480897#M286680</guid>
      <dc:creator>frupaul</dc:creator>
      <dc:date>2018-07-24T18:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: Quoted spaces at end of Macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480899#M286681</link>
      <description>&lt;P&gt;Just use 3 SELECT statements instead of 1.&amp;nbsp; Each can have its own WHERE clause, such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select quote(trim(House)) into :List_house separated by ' '&amp;nbsp; where house &amp;gt; ' '&amp;nbsp; from categories;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 19:00:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480899#M286681</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-24T19:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: Quoted spaces at end of Macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480902#M286682</link>
      <description>&lt;P&gt;I had that as an option. However the data i have posted on here only contains 3 Fields. The original data I am working with contains 35 Fields.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was hoping there will be a direct way to accomplish that&amp;nbsp;with one proc sql&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 19:03:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480902#M286682</guid>
      <dc:creator>frupaul</dc:creator>
      <dc:date>2018-07-24T19:03:39Z</dc:date>
    </item>
    <item>
      <title>Re: Quoted spaces at end of Macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480904#M286683</link>
      <description>&lt;P&gt;Not in a single select statement since you have missing values. Use different select statements&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
infile datalines dlm=',' dsd missover;
input House $ Portfolio $ City $;
datalines;
eson Str,1,London
Portabello,2,Peru
Munopolis,3,Lisbon
duncaster,4,New York
,5,Los Angeles
,6,
,7,
,8,
;
run;

 proc sql ;
select quote(trim(House)) into:List_house separated by ''
	from test
	where House is not null;
select quote(trim(Portfolio)) into:List_portfolio separated by ''
	from test
	where Portfolio is not null;
select quote(trim(City)) into:List_city separated by ''
	from test
	where City is not null;
quit;

%put &amp;amp;List_house;
%put &amp;amp;List_portfolio;
%put &amp;amp;List_city;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Jul 2018 19:07:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480904#M286683</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-07-24T19:07:19Z</dc:date>
    </item>
    <item>
      <title>Re: Quoted spaces at end of Macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480905#M286684</link>
      <description>&lt;P&gt;You still only need one PROC SQL.&amp;nbsp; Multiple SELECT statements are allowed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's probably easiest and clearest to write a small macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro onelist (varname);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select quote(trim(&amp;amp;varname)) into :List_&amp;amp;varname separated by ' '&amp;nbsp; where &amp;amp;varname &amp;gt; ' '&amp;nbsp; from categories;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mend one_list;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can go with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;%onelist (house)&lt;/P&gt;
&lt;P&gt;%onelist (portfolio)&lt;/P&gt;
&lt;P&gt;%onelist (city)&lt;/P&gt;
&lt;P&gt;etc.&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Less typing, definitely less error-prone.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 19:08:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480905#M286684</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-24T19:08:12Z</dc:date>
    </item>
    <item>
      <title>Re: Quoted spaces at end of Macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480913#M286685</link>
      <description>&lt;P&gt;This sounds like a sensible approach. However, all these codes i have written are part of a macro I am building. Can i create a macro within a macro? That would be the solution if that is possible&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 19:26:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480913#M286685</guid>
      <dc:creator>frupaul</dc:creator>
      <dc:date>2018-07-24T19:26:57Z</dc:date>
    </item>
    <item>
      <title>Re: Quoted spaces at end of Macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480914#M286686</link>
      <description>&lt;P&gt;I strongly suspect you're building something better done with formats.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please consider looking into&amp;nbsp; it first before building these macro variable lists.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Either way, add a filter to the where clause to avoid selecting missing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where not missing(house);

or 

where not missing(city);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Jul 2018 19:27:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480914#M286686</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-24T19:27:14Z</dc:date>
    </item>
    <item>
      <title>Re: Quoted spaces at end of Macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480917#M286687</link>
      <description>&lt;P&gt;There's no need to create a macro within a macro.&amp;nbsp; (That would be bad practice.)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just create two macros.&amp;nbsp; One macro is allowed to call another macro.&amp;nbsp; The only requirement is that both macros have to exist when you actually execute the code.&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 19:34:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480917#M286687</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-24T19:34:00Z</dc:date>
    </item>
    <item>
      <title>Re: Quoted spaces at end of Macro variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480951#M286688</link>
      <description>&lt;P&gt;Use a CASE statement to avoid adding quotes around missing values.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make a space delimited list instead of comma delimited list to avoid the extra commas.&amp;nbsp; SAS doesn't need commas between the values in the list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint ;
 select case when missing(city) then city else quote(trim(city)) end
      , case when missing(house) then house else quote(trim(house)) end
  into :city_list separated by ' '
     , :house_list separated by ' '
  from test
 ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;If you want to you can remove the trailing unquoted (and un-macro quoted) spaces&amp;nbsp;with a simple %LET . But is it probably not needed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let city_list=&amp;amp;city_list;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 21:39:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quoted-spaces-at-end-of-Macro-variable-list/m-p/480951#M286688</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-07-24T21:39:08Z</dc:date>
    </item>
  </channel>
</rss>

