<?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 can i use macro in scan function? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-can-i-use-macro-in-scan-function-how-can-i-define-quot-quot/m-p/895338#M353738</link>
    <description>&lt;P&gt;thanks, it works with " |"&amp;nbsp; as delimiter but i could not find the define comma as delimiter.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 21 Sep 2023 19:33:54 GMT</pubDate>
    <dc:creator>alparle</dc:creator>
    <dc:date>2023-09-21T19:33:54Z</dc:date>
    <item>
      <title>how can i use macro in scan function? how can i define "," as delimiter?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-i-use-macro-in-scan-function-how-can-i-define-quot-quot/m-p/895268#M353699</link>
      <description>&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;%let alparle = NCEPA7,NCEPA8;&amp;nbsp; &amp;nbsp;(note: ncepa7 and ncepa8 are names of variables in work.datahave)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;proc sql;&amp;nbsp;&amp;nbsp;create table levo as select ALT,&lt;/DIV&gt;&lt;DIV&gt;scan("&amp;amp;alparle." ,1,&amp;nbsp; ",")&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;from work.datahave ; quit;&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;i want to call only NCEPA7 as variable to my table but the scan function output is "ncepa7" for this reason,&lt;/DIV&gt;&lt;DIV&gt;my tablo look like as :&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;ALT&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;_TEMA001&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ANC&lt;/TD&gt;&lt;TD&gt;NCEPA7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;NON_MARK&lt;/TD&gt;&lt;TD&gt;NCEPA7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;MARK_SPEC&lt;/TD&gt;&lt;TD&gt;NCEPA7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ANC&lt;/TD&gt;&lt;TD&gt;NCEPA7&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;DIV&gt;But i want to get the table as :&lt;/DIV&gt;&lt;DIV&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;ALT&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;NCEPA7&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ANC&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;NON_MARK&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;MARK_SPEC&lt;/TD&gt;&lt;TD&gt;15&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ANC&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;so which function should i use or how can i eliminate the&amp;nbsp; quotation marks?&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;thank you in advance Best Regards.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 21 Sep 2023 19:26:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-i-use-macro-in-scan-function-how-can-i-define-quot-quot/m-p/895268#M353699</guid>
      <dc:creator>alparle</dc:creator>
      <dc:date>2023-09-21T19:26:41Z</dc:date>
    </item>
    <item>
      <title>Re: how can i use macro in scan function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-i-use-macro-in-scan-function-how-can-i-define-quot-quot/m-p/895275#M353702</link>
      <description>&lt;P&gt;&lt;SPAN&gt;You just need to change this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;scan("&amp;amp;alparle." ,1,&amp;nbsp; ",")&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;to this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;scan(&amp;amp;alparle ,1,&amp;nbsp; ",")&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;This will give you the output you showed.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 14:46:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-i-use-macro-in-scan-function-how-can-i-define-quot-quot/m-p/895275#M353702</guid>
      <dc:creator>russt_sas</dc:creator>
      <dc:date>2023-09-21T14:46:13Z</dc:date>
    </item>
    <item>
      <title>Re: how can i use macro in scan function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-i-use-macro-in-scan-function-how-can-i-define-quot-quot/m-p/895279#M353705</link>
      <description>&lt;P&gt;I'm confused, if NCEP7 is a variable that exists in datahave, what are its values? It looks like you're trying to overwrite that variable with new values (5, 7, 15, 1)?&amp;nbsp; What is the meaning of those new values, how do you want to calculate them?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 14:55:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-i-use-macro-in-scan-function-how-can-i-define-quot-quot/m-p/895279#M353705</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-09-21T14:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: how can i use macro in scan function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-i-use-macro-in-scan-function-how-can-i-define-quot-quot/m-p/895300#M353721</link>
      <description>&lt;P&gt;When you run this code:&lt;/P&gt;
&lt;PRE&gt;%let alparle = NCEPA7,NCEPA8;   (note: ncepa7 and ncepa8 are names of variables in work.datahave)
 
proc sql;  create table levo as select ALT,
scan("&amp;amp;alparle." ,1,  ",") 
from work.datahave ; quit;  
 &lt;/PRE&gt;
&lt;P&gt;The macro variable Alparle is replaced by the defintion.&lt;/P&gt;
&lt;P&gt;So SAS sees this as code:&lt;/P&gt;
&lt;PRE&gt;%let alparle = NCEPA7,NCEPA8;   (note: ncepa7 and ncepa8 are names of variables in work.datahave)
 
proc sql;  create table levo as select ALT,
scan("NCEPA7,NCEPA8" ,1,  ",") 
from work.datahave ; quit;  
 &lt;/PRE&gt;
&lt;P&gt;So the SCAN finds the first result in the literal string which is NCEPA7&lt;/P&gt;
&lt;P&gt;If&amp;nbsp; you expect SAS to use code something like this where NCEPA7 is a variable in the Datahave:&lt;/P&gt;
&lt;PRE&gt;proc sql;  create table levo as select ALT,
NCEPA7 
from work.datahave ; quit;  &lt;/PRE&gt;
&lt;P&gt;And especially if you expect to go on to creating some sort of loop to get multiple variables you should describe the whole problem.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 16:22:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-i-use-macro-in-scan-function-how-can-i-define-quot-quot/m-p/895300#M353721</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-09-21T16:22:04Z</dc:date>
    </item>
    <item>
      <title>Re: how can i use macro in scan function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-i-use-macro-in-scan-function-how-can-i-define-quot-quot/m-p/895302#M353723</link>
      <description>&lt;P&gt;If you want to generate code then use MACRO LOGIC and not SAS LOGIC.&lt;/P&gt;
&lt;P&gt;So use the macro function %SCAN() instead of the SAS function SCAN().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note it will be much easier if you use any other character then comma.&amp;nbsp; For example you could use |.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let alparle = NCEPA7|NCEPA8;  
proc sql;
create table levo as 
  select ALT, %scan(&amp;amp;alparle.,1,|) 
  from work.datahave 
; 
quit;  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if you want to use your variable list in normal SAS code then use space as the delimiter.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let alparle = NCEPA7 NCEPA8;  
data levo_alparle;
  set datahave (keep=alt &amp;amp;alparle);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To tell %SCAN() that space is the delimiter use macro quoting.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let alparle = NCEPA7 NCEPA8;  
proc sql;
create table levo as 
  select ALT, %scan(&amp;amp;alparle.,1,%str( )) 
  from work.datahave 
; 
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 16:31:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-i-use-macro-in-scan-function-how-can-i-define-quot-quot/m-p/895302#M353723</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-21T16:31:50Z</dc:date>
    </item>
    <item>
      <title>Re: how can i use macro in scan function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-i-use-macro-in-scan-function-how-can-i-define-quot-quot/m-p/895338#M353738</link>
      <description>&lt;P&gt;thanks, it works with " |"&amp;nbsp; as delimiter but i could not find the define comma as delimiter.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 19:33:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-i-use-macro-in-scan-function-how-can-i-define-quot-quot/m-p/895338#M353738</guid>
      <dc:creator>alparle</dc:creator>
      <dc:date>2023-09-21T19:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: how can i use macro in scan function?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-can-i-use-macro-in-scan-function-how-can-i-define-quot-quot/m-p/895341#M353741</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/453548"&gt;@alparle&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;thanks, it works with " |"&amp;nbsp; as delimiter but i could not find the define comma as delimiter.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So if you use " |" as the delimiter in a %SCAN() call that means that it should treat any of the three characters double quote, space or vertical bar as a possible delimiter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to use comma as the delimiter then you need to use macro quoting (or actual quoting) to make sure the commas do not get seen by SAS as argument delimiters instead of as part of the string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro quoting:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let alparle = NCEPA7,NCEPA8;  
proc sql;  
create table levo as
  select ALT, %scan(%quote(&amp;amp;alparle),1,%str(,)) 
  from work.datahave 
; 
quit;  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Actual quote characters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let alparle = NCEPA7,NCEPA8;  
proc sql;  
create table levo as
  select ALT, %scan("&amp;amp;alparle",1,",") 
  from work.datahave 
; 
quit;  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The only added value of throwing space in as an additional delimiter characters is eliminates any spaces that might exist around the actual delimiters.&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;48   %let list= A  ,  B;
49   %put |%scan("&amp;amp;list",1,",")|;
|A  |
50   %put |%scan("&amp;amp;list",1," ,")|;
|A|
&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Sep 2023 19:48:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-can-i-use-macro-in-scan-function-how-can-i-define-quot-quot/m-p/895341#M353741</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-21T19:48:40Z</dc:date>
    </item>
  </channel>
</rss>

