<?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 scanning macro which has a list of variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/scanning-macro-which-has-a-list-of-variables/m-p/689146#M209475</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am trying to scan a list of variables which are in a macro. When I did harcoding it is working fine and when I am extracting them from a proc sql select into, I am not getting expected result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Success one(hardcode): It is perfectly giving output&lt;/P&gt;
&lt;P&gt;%let type_list = %str("Hybrid","SUV","Sedan","Sports","Truck","Wagon");&lt;BR /&gt;%macro type_c;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;%do i = 1 %to %sysfunc(count(&amp;amp;type_list.,%str(,))) +1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %let type = %scan(&amp;amp;type_list.,&amp;amp;i.,',');&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%put &amp;amp;i. is &amp;amp;type.;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%type_c;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ISSUE:&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;select distinct quote(strip(type)) into :typ_list separated by "," from sashelp.cars;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;typ_list.;&lt;BR /&gt;%macro type_c2;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %do i = 1 %to %sysfunc(count((&amp;amp;typ_list.),%str(,))) +1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %let type2 = %scan((&amp;amp;typ_list.),&amp;amp;i.,',');&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %put &amp;amp;i. is &amp;amp;type2.;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;%end;&lt;BR /&gt;%mend;&lt;/P&gt;
&lt;P&gt;%type_c2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This one is giving output&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 is ("Hybrid"&lt;/P&gt;
&lt;P&gt;2 is "SUV"&lt;/P&gt;
&lt;P&gt;3 is "Sedan"&lt;/P&gt;
&lt;P&gt;4 is "Sports"&lt;/P&gt;
&lt;P&gt;5 is "Truck"&lt;/P&gt;
&lt;P&gt;6 is "Wagon")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the 1st one and 6th one are getting braces in their output which I don't want.&lt;/P&gt;
&lt;P&gt;if I give statement by removing braces aroung &amp;amp;typ_lst. in scan function, I am getting error.&lt;/P&gt;
&lt;P&gt;%let type2 = %scan(&amp;amp;typ_list.)&amp;amp;i.,',');&lt;/P&gt;
&lt;P&gt;%scan and %sysfunc(scan) giving same result.&lt;/P&gt;
&lt;P&gt;I want output of 1st and 6th one without braces like rest all.&lt;/P&gt;</description>
    <pubDate>Tue, 06 Oct 2020 11:01:21 GMT</pubDate>
    <dc:creator>pessi</dc:creator>
    <dc:date>2020-10-06T11:01:21Z</dc:date>
    <item>
      <title>scanning macro which has a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scanning-macro-which-has-a-list-of-variables/m-p/689146#M209475</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am trying to scan a list of variables which are in a macro. When I did harcoding it is working fine and when I am extracting them from a proc sql select into, I am not getting expected result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Success one(hardcode): It is perfectly giving output&lt;/P&gt;
&lt;P&gt;%let type_list = %str("Hybrid","SUV","Sedan","Sports","Truck","Wagon");&lt;BR /&gt;%macro type_c;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;%do i = 1 %to %sysfunc(count(&amp;amp;type_list.,%str(,))) +1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %let type = %scan(&amp;amp;type_list.,&amp;amp;i.,',');&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%put &amp;amp;i. is &amp;amp;type.;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;%end;&lt;BR /&gt;%mend;&lt;BR /&gt;%type_c;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ISSUE:&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;select distinct quote(strip(type)) into :typ_list separated by "," from sashelp.cars;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;typ_list.;&lt;BR /&gt;%macro type_c2;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; %do i = 1 %to %sysfunc(count((&amp;amp;typ_list.),%str(,))) +1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %let type2 = %scan((&amp;amp;typ_list.),&amp;amp;i.,',');&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; %put &amp;amp;i. is &amp;amp;type2.;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;%end;&lt;BR /&gt;%mend;&lt;/P&gt;
&lt;P&gt;%type_c2;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This one is giving output&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 is ("Hybrid"&lt;/P&gt;
&lt;P&gt;2 is "SUV"&lt;/P&gt;
&lt;P&gt;3 is "Sedan"&lt;/P&gt;
&lt;P&gt;4 is "Sports"&lt;/P&gt;
&lt;P&gt;5 is "Truck"&lt;/P&gt;
&lt;P&gt;6 is "Wagon")&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the 1st one and 6th one are getting braces in their output which I don't want.&lt;/P&gt;
&lt;P&gt;if I give statement by removing braces aroung &amp;amp;typ_lst. in scan function, I am getting error.&lt;/P&gt;
&lt;P&gt;%let type2 = %scan(&amp;amp;typ_list.)&amp;amp;i.,',');&lt;/P&gt;
&lt;P&gt;%scan and %sysfunc(scan) giving same result.&lt;/P&gt;
&lt;P&gt;I want output of 1st and 6th one without braces like rest all.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Oct 2020 11:01:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scanning-macro-which-has-a-list-of-variables/m-p/689146#M209475</guid>
      <dc:creator>pessi</dc:creator>
      <dc:date>2020-10-06T11:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: scanning macro which has a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scanning-macro-which-has-a-list-of-variables/m-p/689157#M209478</link>
      <description>&lt;P&gt;Your code shows&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let type2 = %scan((&amp;amp;typ_list.),&amp;amp;i.,',');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and so when you put parentheses around &amp;amp;typ_list, this is just adding the text ( at the left and adding the text ) at the right of &amp;amp;typ_list, which then gives ("Hybrid","SUV","Sedan","Sports","Truck","Wagon") as the argument to the %SCAN function. So the %SCAN function finds the first text string as ("Hybrid"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think what you want is this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let type2 = %scan(%bquote(&amp;amp;typ_list.),&amp;amp;i.,',');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The %quote masks the commas inside &amp;amp;typ_list so they are not used as a separator of different arguments to %SCAN, and the parentheses in %BQUOTE( ) are not interpreted as being added to the text string.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Oct 2020 11:23:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scanning-macro-which-has-a-list-of-variables/m-p/689157#M209478</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-06T11:23:06Z</dc:date>
    </item>
    <item>
      <title>Re: scanning macro which has a list of variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/scanning-macro-which-has-a-list-of-variables/m-p/689159#M209480</link>
      <description>yes.. It worked.. Thanks &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;.</description>
      <pubDate>Tue, 06 Oct 2020 11:27:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/scanning-macro-which-has-a-list-of-variables/m-p/689159#M209480</guid>
      <dc:creator>pessi</dc:creator>
      <dc:date>2020-10-06T11:27:51Z</dc:date>
    </item>
  </channel>
</rss>

