<?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: Substring multiple variables with same prefix in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Substring-multiple-variables-with-same-prefix/m-p/632845#M187671</link>
    <description>Thanks. Exactly!</description>
    <pubDate>Wed, 18 Mar 2020 03:18:28 GMT</pubDate>
    <dc:creator>Cruise</dc:creator>
    <dc:date>2020-03-18T03:18:28Z</dc:date>
    <item>
      <title>Substring multiple variables with same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substring-multiple-variables-with-same-prefix/m-p/632842#M187668</link>
      <description>&lt;P&gt;Hi Folks:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd like to substring the first 3 digits of multiple variables all initialized with dx. In real dataset, I have dx01-25. My code posted below doesn't work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please help correct the existing code or suggest alternative approach to substring all dx01-dx25 without substr each variable individually?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your time in advance.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input dx01 $ dx02 $ dx03 $ case;
cards;
15701 1576	2007 1
15701 2006	1007 1
10001 1576  1007 1
;
data want; set have;
  array diag[*] dx01-dx03;
  do i = 1 to dim(diag);
  dx=diag[i];
  DX_substr=substr(left(dx),1,3);
end;
drop i; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 02:54:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substring-multiple-variables-with-same-prefix/m-p/632842#M187668</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2020-03-18T02:54:50Z</dc:date>
    </item>
    <item>
      <title>Re: Substring multiple variables with same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substring-multiple-variables-with-same-prefix/m-p/632843#M187669</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
  input DX01 $ DX02 $ DX03 $ CASE;
cards;
15701 1576 2007 1
15701 2006 1007 1
10001 1576 1007 1
;
data WANT; 
  set HAVE;
  array DXIN [3] DX01-DX03;
  array DXOUT[3] ;
  do I = 1 to dim(DXIN);
    DXOUT[I]=substr(left(DXIN[I]),1,3);
  end;
  drop I; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;TABLE style="border-collapse: collapse; width: 336pt;" border="0" width="448" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD width="64" height="21" class="xl65" style="height: 15.75pt; width: 48pt;"&gt;DX01&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;DX02&lt;/TD&gt;
&lt;TD width="64" class="xl66" style="width: 48pt;"&gt;DX03&lt;/TD&gt;
&lt;TD width="64" class="xl67" style="width: 48pt;"&gt;CASE&lt;/TD&gt;
&lt;TD width="64" class="xl67" style="width: 48pt;"&gt;DXOUT1&lt;/TD&gt;
&lt;TD width="64" class="xl67" style="width: 48pt;"&gt;DXOUT2&lt;/TD&gt;
&lt;TD width="64" class="xl68" style="width: 48pt;"&gt;DXOUT3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl69" style="height: 15.75pt;"&gt;15701&lt;/TD&gt;
&lt;TD class="xl63"&gt;1576&lt;/TD&gt;
&lt;TD class="xl63"&gt;2007&lt;/TD&gt;
&lt;TD class="xl64"&gt;1&lt;/TD&gt;
&lt;TD class="xl64"&gt;157&lt;/TD&gt;
&lt;TD class="xl64"&gt;157&lt;/TD&gt;
&lt;TD class="xl70"&gt;200&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.75pt;"&gt;
&lt;TD height="21" class="xl69" style="height: 15.75pt;"&gt;15701&lt;/TD&gt;
&lt;TD class="xl63"&gt;2006&lt;/TD&gt;
&lt;TD class="xl63"&gt;1007&lt;/TD&gt;
&lt;TD class="xl64"&gt;1&lt;/TD&gt;
&lt;TD class="xl64"&gt;157&lt;/TD&gt;
&lt;TD class="xl64"&gt;200&lt;/TD&gt;
&lt;TD class="xl70"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 15.0pt;"&gt;
&lt;TD height="20" class="xl71" style="height: 15.0pt;"&gt;10001&lt;/TD&gt;
&lt;TD class="xl72"&gt;1576&lt;/TD&gt;
&lt;TD class="xl72"&gt;1007&lt;/TD&gt;
&lt;TD class="xl73"&gt;1&lt;/TD&gt;
&lt;TD class="xl73"&gt;100&lt;/TD&gt;
&lt;TD class="xl73"&gt;157&lt;/TD&gt;
&lt;TD class="xl74"&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&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, 18 Mar 2020 03:04:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substring-multiple-variables-with-same-prefix/m-p/632843#M187669</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-03-18T03:04:44Z</dc:date>
    </item>
    <item>
      <title>Re: Substring multiple variables with same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substring-multiple-variables-with-same-prefix/m-p/632845#M187671</link>
      <description>Thanks. Exactly!</description>
      <pubDate>Wed, 18 Mar 2020 03:18:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substring-multiple-variables-with-same-prefix/m-p/632845#M187671</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2020-03-18T03:18:28Z</dc:date>
    </item>
    <item>
      <title>Re: Substring multiple variables with same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substring-multiple-variables-with-same-prefix/m-p/632852#M187675</link>
      <description>&lt;P&gt;Another way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT; 
  set HAVE;
  array DXIN     DX01  - DX03  ;
  array DXOUT $3 DXO01 - DXO03 ;
  do over DXIN;
    DXOUT=DXIN;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 04:18:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substring-multiple-variables-with-same-prefix/m-p/632852#M187675</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-03-18T04:18:48Z</dc:date>
    </item>
    <item>
      <title>Re: Substring multiple variables with same prefix</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substring-multiple-variables-with-same-prefix/m-p/633007#M187746</link>
      <description>&lt;P&gt;Depending on what need the truncated versions for you may need even need to change the data. Use a format for display or group creation purposes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data HAVE;
  input DX01 $ DX02 $ DX03 $ CASE;
cards;
15701 1576 2007 1
15701 2006 1007 1
10001 1576 1007 1
;

proc print data=have;
   format dx: $3.;
run;&lt;/PRE&gt;
&lt;P&gt;The groups created by using a different format would be honored in most of the analysis, reporting or graphic procedures.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Mar 2020 16:10:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substring-multiple-variables-with-same-prefix/m-p/633007#M187746</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-03-18T16:10:38Z</dc:date>
    </item>
  </channel>
</rss>

