<?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: Macro variable with hyphen used in scan function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415676#M101974</link>
    <description>&lt;P&gt;Make sure to use the right delimiter list. It is easier to use an iterative do loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let rx_list=ACE ACE-ARB ACE-DIU ARB ARB-ACE-DIU ARB-DIU;
%do i=1 %to %sysfunc(countw(&amp;amp;rx_list,%str( ));
   %let next=%scan(&amp;amp;rx_list,&amp;amp;i,%str( ));
%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 22 Nov 2017 21:43:15 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-11-22T21:43:15Z</dc:date>
    <item>
      <title>Macro variable with hyphen used in scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415623#M101950</link>
      <description>&lt;P&gt;I have a macro variable that contains hyphens and which are not correctly read by the scan function.&amp;nbsp; The scan function treats the hyphens as delimiters.&amp;nbsp; How do I stop this?&amp;nbsp; My guess is that it is a modifier in the scan function, but which one?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;rx_list looks like this: ACE ACE-ARB ACE-DIU ARB ARB-ACE-DIU ARB-DIU&lt;/P&gt;&lt;P&gt;instead of reading it in as 6 different values, it creates 11 in the following macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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 name into : rx_list by ' ' from orig_data;


quit;





%macro rx_pre;


  %local I next_rx;


  %let I=1;


  %do %while (%scan(rx_list, &amp;amp;i) ne);


    %let next_rx=%scan(&amp;amp;rx_list, &amp;amp;i);


       ... data step ...


    %let i=&amp;amp;eval(&amp;amp;i+1);


  %end;


%mend;





%rx_pre;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Nov 2017 19:30:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415623#M101950</guid>
      <dc:creator>akj</dc:creator>
      <dc:date>2017-11-22T19:30:55Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with hyphen used in scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415634#M101955</link>
      <description>&lt;P&gt;The default delimiter in SCAN is spaces. You can specify custom delimiters using the third parameter option.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 19:46:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415634#M101955</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-22T19:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with hyphen used in scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415636#M101956</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In your proc step SEPARATED is missing&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 19:52:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415636#M101956</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2017-11-22T19:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with hyphen used in scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415640#M101957</link>
      <description>&lt;P&gt;Hyphen is one of the many default delimiters that %SCAN() will use if you do not give it the delimiter you want to use.&lt;/P&gt;
&lt;P&gt;Tell %SCAN() that you only want to use space as the delimiter.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do %while (%scan(rx_list, &amp;amp;i,%str( )) ne);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or use some other delimiter.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;...
into :rx_list separated by '|' 
...
%scan(&amp;amp;rx_list,&amp;amp;i,|)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 20:21:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415640#M101957</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-22T20:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with hyphen used in scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415642#M101958</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input name $20.;&lt;BR /&gt;datalines;&lt;BR /&gt;ACE&lt;BR /&gt;ACE-ARB&lt;BR /&gt;ACE-DIU&lt;BR /&gt;ARB&lt;BR /&gt;ARB-ACE-DIU&lt;BR /&gt;ARB-DIU&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql ;&lt;BR /&gt;select name,count(*) into : rx_list separated by "|" ,:count&lt;BR /&gt;from have;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%macro rx_pre;&lt;BR /&gt;DATA test;&lt;BR /&gt;%do i=1 %to &amp;amp;count;&lt;BR /&gt;%let next_rx=%scan(&amp;amp;rx_list,&amp;amp;i,"|");&lt;BR /&gt;Var_&amp;amp;i="&amp;amp;next_rx.";&lt;BR /&gt;%end;&lt;BR /&gt;RUN;&lt;BR /&gt;%mend;&lt;BR /&gt;%rx_pre;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 20:10:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415642#M101958</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2017-11-22T20:10:10Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with hyphen used in scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415657#M101965</link>
      <description>Thanks. It got lost in the transcription.</description>
      <pubDate>Wed, 22 Nov 2017 20:40:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415657#M101965</guid>
      <dc:creator>akj</dc:creator>
      <dc:date>2017-11-22T20:40:17Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with hyphen used in scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415658#M101966</link>
      <description>&lt;P&gt;I tried the '|' and the first iteration of the macro works fine, but it gets hung up on the second with an error message: "A character operand was found in the %eval function or %IF condition where a numeric operand is required. The condition was %scan(&amp;amp;rx_list, &amp;amp;i, '|') ne"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 20:43:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415658#M101966</guid>
      <dc:creator>akj</dc:creator>
      <dc:date>2017-11-22T20:43:24Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with hyphen used in scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415659#M101967</link>
      <description>Thank you for the suggestion, but I am getting the values from a dataset.</description>
      <pubDate>Wed, 22 Nov 2017 20:44:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415659#M101967</guid>
      <dc:creator>akj</dc:creator>
      <dc:date>2017-11-22T20:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with hyphen used in scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415663#M101968</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/82408"&gt;@akj&lt;/a&gt;&amp;nbsp;The first step is in the solution to create fake data to demonstrate how the code works. It’s known as a fully worked example/reproducible example.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We don’t have your data or code to work with, so we can either make suggestions or make demo data to work with. Personally, I won’t take the time to make demo data anymore, but&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/83078"&gt;@SuryaKiran&lt;/a&gt;&amp;nbsp;has take the time to make demo data to demonstrate a solution to your problem.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 21:00:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415663#M101968</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-22T21:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with hyphen used in scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415673#M101972</link>
      <description>&lt;P&gt;Why did you include quotes in the list of delimiters you passed to the %SCAN() function?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro rx_pre;
DATA test;
%do i=1 %to &amp;amp;count;
%let next_rx=%scan(&amp;amp;rx_list,&amp;amp;i,|);
 Var_&amp;amp;i="&amp;amp;next_rx.";
%end;
RUN;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 21:34:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415673#M101972</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-22T21:34:06Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with hyphen used in scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415674#M101973</link>
      <description>&lt;P&gt;Why did you include quotes in the list of delimiters you passed to the %SCAN() function?&amp;nbsp; Do you actually have quote characters in your data?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 21:35:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415674#M101973</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-22T21:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with hyphen used in scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415676#M101974</link>
      <description>&lt;P&gt;Make sure to use the right delimiter list. It is easier to use an iterative do loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let rx_list=ACE ACE-ARB ACE-DIU ARB ARB-ACE-DIU ARB-DIU;
%do i=1 %to %sysfunc(countw(&amp;amp;rx_list,%str( ));
   %let next=%scan(&amp;amp;rx_list,&amp;amp;i,%str( ));
%end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Nov 2017 21:43:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415676#M101974</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-22T21:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable with hyphen used in scan function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415715#M101999</link>
      <description>&lt;P&gt;No, I don't and removing them seems to have solved the issue.&amp;nbsp; Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 23:19:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-with-hyphen-used-in-scan-function/m-p/415715#M101999</guid>
      <dc:creator>akj</dc:creator>
      <dc:date>2017-11-22T23:19:19Z</dc:date>
    </item>
  </channel>
</rss>

