<?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: Using %Scan inside quotes in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-Scan-inside-quotes/m-p/642277#M191573</link>
    <description>&lt;P&gt;Get the SAS code working before introducing macro variables and/or macro logic.&lt;/P&gt;
&lt;P&gt;So start with your first program that just has one value as constant text.&amp;nbsp; Now write SAS code that deals with parsing one value from a longer string.&amp;nbsp; For that you would use the SCAN() function (not the macro function %SCAN()).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;If VARIABLE = scan("Los Angeles,New York",1,',') then delete;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now if you have a macro variable VIST with that text.&amp;nbsp; Like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let vist=Los Angeles,New York;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use it in place of the literal text.&amp;nbsp; Make sure to use double quotes and not single quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;If VARIABLE = scan("&amp;amp;visit",1,',') then delete;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 23 Apr 2020 15:07:36 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-04-23T15:07:36Z</dc:date>
    <item>
      <title>Using %Scan inside quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Scan-inside-quotes/m-p/642252#M191565</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a list of variable. When running&amp;nbsp; %scan((&amp;amp;vlist.),3,","); I obtain the character string "Los Angeles" but not inside "". Now I want to delete the observations when my character variable VAR takes the value "Los Angeles".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, i'm looking to run this code, but precising that the result of the %scan() function is a character string :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data Want;&lt;BR /&gt;set Have;&lt;BR /&gt;If VARIABLE = %scan((&amp;amp;vlist.),3,",") then delete;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For information, when running :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data Want;&lt;BR /&gt;set Have;&lt;BR /&gt;If VARIABLE = "Los Angeles" then delete;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get the result that I want.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 14:37:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Scan-inside-quotes/m-p/642252#M191565</guid>
      <dc:creator>Mathis1</dc:creator>
      <dc:date>2020-04-23T14:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using %Scan inside quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Scan-inside-quotes/m-p/642255#M191567</link>
      <description>&lt;P&gt;Ok, I managed to do it actually.&lt;/P&gt;&lt;P&gt;Sorry for the post &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 14:39:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Scan-inside-quotes/m-p/642255#M191567</guid>
      <dc:creator>Mathis1</dc:creator>
      <dc:date>2020-04-23T14:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using %Scan inside quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Scan-inside-quotes/m-p/642262#M191569</link>
      <description>&lt;P&gt;Why are you using %scan, if your code is not part of a macro program?&lt;/P&gt;
&lt;P&gt;What does &amp;amp;vlist contain?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I seems to me that you may want use one of next functions:&lt;/P&gt;
&lt;P&gt;index() or find() instead %scan.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 14:42:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Scan-inside-quotes/m-p/642262#M191569</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-04-23T14:42:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using %Scan inside quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Scan-inside-quotes/m-p/642263#M191570</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Want;
set Have;
If VARIABLE = scan("&amp;amp;vlist",3,",") then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Apr 2020 14:43:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Scan-inside-quotes/m-p/642263#M191570</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-04-23T14:43:35Z</dc:date>
    </item>
    <item>
      <title>Re: Using %Scan inside quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Scan-inside-quotes/m-p/642277#M191573</link>
      <description>&lt;P&gt;Get the SAS code working before introducing macro variables and/or macro logic.&lt;/P&gt;
&lt;P&gt;So start with your first program that just has one value as constant text.&amp;nbsp; Now write SAS code that deals with parsing one value from a longer string.&amp;nbsp; For that you would use the SCAN() function (not the macro function %SCAN()).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;If VARIABLE = scan("Los Angeles,New York",1,',') then delete;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now if you have a macro variable VIST with that text.&amp;nbsp; Like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let vist=Los Angeles,New York;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can use it in place of the literal text.&amp;nbsp; Make sure to use double quotes and not single quotes.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;If VARIABLE = scan("&amp;amp;visit",1,',') then delete;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Apr 2020 15:07:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Scan-inside-quotes/m-p/642277#M191573</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-04-23T15:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: Using %Scan inside quotes</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-Scan-inside-quotes/m-p/642300#M191578</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a macro variable holding a comma delimited list like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let vlist=Los Angeles,New York,Providence;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you can use %SCAN inside of double quotes, no problem.&amp;nbsp; The only trick is you need to add macro quoting, to mask the commas.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;If VARIABLE = "%scan(%bquote(&amp;amp;vlist),1,%str(,))" then delete;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I think that's a reasonable use of the macro language.&amp;nbsp; It could even execute faster that changing to use the scan function, depending on whether or not the data step compiler is smart enough to realize that&amp;nbsp; something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;scan("Los Angeles,New York,Providence",1,',')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;only needs to execute scan once.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 15:31:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-Scan-inside-quotes/m-p/642300#M191578</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2020-04-23T15:31:27Z</dc:date>
    </item>
  </channel>
</rss>

