<?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 get each word in macro variable wrapped by quotation marks(&amp;quot; &amp;quot;)? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-each-word-in-macro-variable-wrapped-by-quotation/m-p/616773#M180627</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let GROUP= SUV Sedan;

data want;
 set sashelp.cars;
 if findw(symget('group'), strip(type) ) ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 12 Jan 2020 11:12:29 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2020-01-12T11:12:29Z</dc:date>
    <item>
      <title>How to get each word in macro variable wrapped by quotation marks(" ")?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-each-word-in-macro-variable-wrapped-by-quotation/m-p/616692#M180570</link>
      <description>&lt;P&gt;Can I change GROUP to GROUP2 systematically?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let GROUP= SUV Sedan;&lt;BR /&gt;%let GROUP2= "SUV" "Sedan";&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;I tried to do this myself using scan function, etc. but didn't manage to do so.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's a simplified example of the situation I am facing. My GROUP variable includes like 100 words and I want to generate GROUP2 macro variable so that I can use it in WHERE statement of data step.&lt;/P&gt;</description>
      <pubDate>Sat, 11 Jan 2020 16:13:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-each-word-in-macro-variable-wrapped-by-quotation/m-p/616692#M180570</guid>
      <dc:creator>braam</dc:creator>
      <dc:date>2020-01-11T16:13:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to get each word in macro variable wrapped by quotation marks(" ")?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-each-word-in-macro-variable-wrapped-by-quotation/m-p/616695#M180573</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let GROUP= SUV Sedan;

%macro t;
 %global group2;
 %do i=1 %to %sysfunc(countw(&amp;amp;group,%str( )));
 %let Group2=&amp;amp;group2 "%scan(&amp;amp;group,&amp;amp;i,%str( ))";
 %end;
%mend t;

%t

%put &amp;amp;=group2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;LOG:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;95   %let GROUP= SUV Sedan;
96
97   %macro t;
98    %global group2;
99    %do i=1 %to %sysfunc(countw(&amp;amp;group,%str( )));
100   %let Group2=&amp;amp;group2 "%scan(&amp;amp;group,&amp;amp;i,%str( ))";
101   %end;
102  %mend t;
103
104  %t
105
106  %put &amp;amp;=group2;
GROUP2="SUV" "Sedan"
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And as a matter of fact, you could use QUOTE function as an alternative to explicit " " quotes like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%macro t;
 %global group2;
 %do i=1 %to %sysfunc(countw(&amp;amp;group,%str( )));
 %let Group2=&amp;amp;group2 %sysfunc(quote(%scan(&amp;amp;group,&amp;amp;i,%str( ))));
 %end;
%mend t;

%t
%put &amp;amp;=group2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Jan 2020 16:41:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-each-word-in-macro-variable-wrapped-by-quotation/m-p/616695#M180573</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-11T16:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to get each word in macro variable wrapped by quotation marks(" ")?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-each-word-in-macro-variable-wrapped-by-quotation/m-p/616697#M180574</link>
      <description>&lt;P&gt;If your list of words is using space as the delimiter then you can do it in one statement using the TRANWRD() function to convert the spaces into quoted spaces.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let group2="%sysfunc(tranwrd(&amp;amp;group,%str( )," "))";&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;263   %let GROUP= SUV Sedan;
264   %let GROUP2= "%sysfunc(tranwrd(&amp;amp;group,%str( )," "))";
265   %put &amp;amp;=group2;
GROUP2="SUV" "Sedan"&lt;/PRE&gt;
&lt;P&gt;Note that the list needs to have one and only one space between the words for this method to work.&amp;nbsp; You can insure that property by using the COMPBL() function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;267   %let GROUP= SUV    Sedan;
268   %let GROUP2= "%sysfunc(tranwrd(%sysfunc(compbl(&amp;amp;group)),%str( )," "))";
269   %put &amp;amp;=group2;
GROUP2="SUV" "Sedan"&lt;/PRE&gt;
&lt;P&gt;Frequently you will want to use single quotes instead of double quotes. For example when the words contain macro triggers, % or &amp;amp;, or when you want to use the resulting string in pass thru SQL to a system that only allows the use of single quotes in character literals.&lt;/P&gt;
&lt;PRE&gt;273   %let GROUP= SUV    Sedan;
274   %let GROUP2= %unquote(%str(%')%qsysfunc(tranwrd(%sysfunc(compbl(&amp;amp;group)),%str( ),' '))%str(%'));
275   %put &amp;amp;=group2;
GROUP2='SUV' 'Sedan'&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that it gets even more complicated if you need to worry about words that contain the quote character itself.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fortunately there are many macros out there that implement some form of adding quotes to lists in macro variables.&amp;nbsp; Here is a link to one adopted from the original %QLIST() macro created by Tom Hoffman 25 years ago.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sasutils/macros/blob/master/qlist.sas" target="_blank" rel="noopener"&gt;https://github.com/sasutils/macros/blob/master/qlist.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Examples:&lt;/P&gt;
&lt;PRE&gt;360   %let GROUP=SUV  Sedan;
361   %put WHERE type in %qlist(&amp;amp;group);
WHERE type in ('SUV','Sedan')
362   %put WHERE type in %qlist(&amp;amp;group,dsd=1);
WHERE type in ('SUV','','Sedan')
363
364   %let group=SUV||Sedan;
365   %put WHERE type in %qlist(&amp;amp;group,delimit=|);
WHERE type in ('SUV','','Sedan')
366   %put WHERE type in %qlist(&amp;amp;group,delimit=|,dsd=0);
WHERE type in ('SUV','Sedan')&lt;/PRE&gt;</description>
      <pubDate>Sat, 11 Jan 2020 17:38:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-each-word-in-macro-variable-wrapped-by-quotation/m-p/616697#M180574</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-01-11T17:38:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to get each word in macro variable wrapped by quotation marks(" ")?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-each-word-in-macro-variable-wrapped-by-quotation/m-p/616700#M180577</link>
      <description>&lt;P&gt;If somehow you are extracting these values from a data set (SUV and SEDAN are values in a data set) then you can use PROC SQL.&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 quote(variablename) into :group separated by ' ' from datasetname;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 11 Jan 2020 17:23:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-each-word-in-macro-variable-wrapped-by-quotation/m-p/616700#M180577</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-11T17:23:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to get each word in macro variable wrapped by quotation marks(" ")?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-each-word-in-macro-variable-wrapped-by-quotation/m-p/616702#M180578</link>
      <description>&lt;P&gt;Sir&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; Very neat and perhaps the best idea to do things in a &lt;U&gt;&lt;STRONG&gt;cleanest way&lt;/STRONG&gt;&lt;/U&gt; possible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just a thought, once the source is a&amp;nbsp; dataset, which makes it easiser to edit/modify with potential to hold numerous values, why bother to even have a macro variable?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not a use the Dataset as a LOOK-UP dataset?&lt;/P&gt;</description>
      <pubDate>Sat, 11 Jan 2020 17:36:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-each-word-in-macro-variable-wrapped-by-quotation/m-p/616702#M180578</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-11T17:36:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to get each word in macro variable wrapped by quotation marks(" ")?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-each-word-in-macro-variable-wrapped-by-quotation/m-p/616733#M180602</link>
      <description>&lt;P&gt;You could do this with a data set as well in many situations. I suppose the advantage of PROC SQL is that you can use DISTINCT if needed, whereas that's not that easy using data sets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Jan 2020 00:13:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-each-word-in-macro-variable-wrapped-by-quotation/m-p/616733#M180602</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-12T00:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to get each word in macro variable wrapped by quotation marks(" ")?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-each-word-in-macro-variable-wrapped-by-quotation/m-p/616772#M180626</link>
      <description>&lt;P&gt;If you want&amp;nbsp;&lt;SPAN&gt;use it in WHERE statement of data step. you could try SYMGET().&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if findw(symget('group'), strip(group) ) then ....&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let GROUP= SUV Sedan;

%let group2="%sysfunc(prxchange(s/\s+/" "/,-1,&amp;amp;group))" ;

%put group=&amp;amp;group ;
%put group2=&amp;amp;group2 ;&lt;/PRE&gt;</description>
      <pubDate>Sun, 12 Jan 2020 11:09:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-each-word-in-macro-variable-wrapped-by-quotation/m-p/616772#M180626</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-01-12T11:09:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to get each word in macro variable wrapped by quotation marks(" ")?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-each-word-in-macro-variable-wrapped-by-quotation/m-p/616773#M180627</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let GROUP= SUV Sedan;

data want;
 set sashelp.cars;
 if findw(symget('group'), strip(type) ) ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 12 Jan 2020 11:12:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-each-word-in-macro-variable-wrapped-by-quotation/m-p/616773#M180627</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-01-12T11:12:29Z</dc:date>
    </item>
  </channel>
</rss>

