<?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: Use %scan to scan character values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-scan-to-scan-character-values/m-p/505840#M135515</link>
    <description>&lt;P&gt;Use a format:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input fc5 $;
datalines;
71234
71333
7149833
;
run;

data cntlin;
input start :$3. label :$12.;
fmtname = 'myfmt';
type = 'C';
datalines;
711 Admin
712 IP
713 AC
714 Diagtherap
715 CommHealth
717 Research
718 Education
719 UndAccnt
run;

proc format cntlin=cntlin;
run;

data want;
set have;
fc_desc = put(substr(fc5,1,3),$myfmt.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 19 Oct 2018 06:30:29 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-10-19T06:30:29Z</dc:date>
    <item>
      <title>Use %scan to scan character values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-scan-to-scan-character-values/m-p/505839#M135514</link>
      <description>&lt;P&gt;I have a list of code and want to take the first 3 digits or 5 digits of values to assign description. Here is just a short list of code and I have descriptions for 8 codes. Can I use %scan to do the job? I'm trying to use more concise code to do the job. Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have; input fc5 $;
datalines;
71234
71333
7149833
;
proc print; run;
%let code= 711 712 713 714 715 717 718 819;		
%let desc= Admin IP AC Diagtherap CommHealth Research Education UndAccnt;
data want; set have;
%macro getdesc ();
%do i=1 %to 8;
if substr(fc5,1,3)=%scan(&amp;amp;code,&amp;amp;i) then fc_desc=%scan("&amp;amp;desc.",i);
%end;
%mend;
%getdesc;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Oct 2018 06:21:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-scan-to-scan-character-values/m-p/505839#M135514</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2018-10-19T06:21:50Z</dc:date>
    </item>
    <item>
      <title>Re: Use %scan to scan character values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-scan-to-scan-character-values/m-p/505840#M135515</link>
      <description>&lt;P&gt;Use a format:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input fc5 $;
datalines;
71234
71333
7149833
;
run;

data cntlin;
input start :$3. label :$12.;
fmtname = 'myfmt';
type = 'C';
datalines;
711 Admin
712 IP
713 AC
714 Diagtherap
715 CommHealth
717 Research
718 Education
719 UndAccnt
run;

proc format cntlin=cntlin;
run;

data want;
set have;
fc_desc = put(substr(fc5,1,3),$myfmt.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Oct 2018 06:30:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-scan-to-scan-character-values/m-p/505840#M135515</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-19T06:30:29Z</dc:date>
    </item>
    <item>
      <title>Re: Use %scan to scan character values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-scan-to-scan-character-values/m-p/505841#M135516</link>
      <description>&lt;P&gt;And even if you use the double macro variables, you would not need a macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let code= 711 712 713 714 715 717 718 819;		
%let desc= Admin IP AC Diagtherap CommHealth Research Education UndAccnt;

data want;
set have;
do i = 1 to 8;
  if substr(fc5,1,3) = scan("&amp;amp;code",i) then fc_desc = scan("&amp;amp;desc.",i);
end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you can clearly see how the format makes the code simple and easy to maintain.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Oct 2018 06:32:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-scan-to-scan-character-values/m-p/505841#M135516</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-19T06:32:12Z</dc:date>
    </item>
    <item>
      <title>Re: Use %scan to scan character values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-scan-to-scan-character-values/m-p/506121#M135615</link>
      <description>&lt;P&gt;Thanks for fixing the code. It worked. Indeed the format will do. The reason I preferred %scan here because I've a long list (longer than the ones shown in my example). and I wanted to use fewer lines to do the job.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Oct 2018 18:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-scan-to-scan-character-values/m-p/506121#M135615</guid>
      <dc:creator>Solph</dc:creator>
      <dc:date>2018-10-19T18:53:00Z</dc:date>
    </item>
  </channel>
</rss>

