<?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: Multiple columns have the same condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-have-the-same-condition/m-p/315150#M68698</link>
    <description>&lt;P&gt;Some questions. &amp;nbsp;Firstly, why are you trying to do this using text numbers? &amp;nbsp;Numeric data types are there for a reason. &amp;nbsp;Secondly, what is the reasoning behind this, newphone would end up looking like:&lt;/P&gt;
&lt;P&gt;0245&lt;/P&gt;
&lt;P&gt;03609&lt;/P&gt;
&lt;P&gt;045907&lt;/P&gt;
&lt;P&gt;Which doesn't really make sense to me. &amp;nbsp;What is col1-col3, it looks from the var name newphone, to be a number, but catting on an 02/03 etc. wouldn't make the result a number. &amp;nbsp;I mean you "could" do:&lt;/P&gt;
&lt;PRE&gt;data have;
  input Acct $ col1 $ col2 $ col3 $;
datalines;
ABC 45 375 89756
TFA 609 8320 835
FGT 5907 561 413
;
run;

data want;
  length newphone $20;
  set have;
  newphone=cats("0",put(lengthn(col1),best.),col1);
run;
&lt;/PRE&gt;
&lt;P&gt;But why?&lt;/P&gt;</description>
    <pubDate>Tue, 29 Nov 2016 11:03:29 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-11-29T11:03:29Z</dc:date>
    <item>
      <title>Multiple columns have the same condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-have-the-same-condition/m-p/315134#M68694</link>
      <description>Hello! My data looks like this:&lt;BR /&gt;Acct col1 col2 col3&lt;BR /&gt;ABC 45   375    89756&lt;BR /&gt;TFA  609  8320 835&lt;BR /&gt;FGT 5907 561 413&lt;BR /&gt;Col1-col3 are character type. &lt;BR /&gt;My code is:&lt;BR /&gt;Data final;set cols;&lt;BR /&gt; If length(col1)&amp;lt;= 2 then code='02'&lt;BR /&gt; Else if lengh(col1)=3 then code ='03;&lt;BR /&gt;Else if length(col1)=4 then code ='04';&lt;BR /&gt;Newphone1=cats(code,col1);&lt;BR /&gt;Run;&lt;BR /&gt;How do i make the code simpler so that i wont have to do a similar data step to col2 and col3?</description>
      <pubDate>Tue, 29 Nov 2016 10:12:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-have-the-same-condition/m-p/315134#M68694</guid>
      <dc:creator>JT99</dc:creator>
      <dc:date>2016-11-29T10:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple columns have the same condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-have-the-same-condition/m-p/315138#M68696</link>
      <description>&lt;P&gt;Use an array.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See an example here:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a001371428.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/viewer.htm#a001371428.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2016 10:23:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-have-the-same-condition/m-p/315138#M68696</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-29T10:23:54Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple columns have the same condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-have-the-same-condition/m-p/315139#M68697</link>
      <description>&lt;P&gt;Something like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Acct $ (col1-col3) ($);
cards;
ABC 45 375 89756
TFA 609 8320 835
FGT 5907 561 413
;
run;

data want;
set have;
array cols {*} col1-col3;
array newphone {*} $ newphone1-newphone3;
do i = 1 to 3;
  newphone{i} = cats(put(length(cols{i}),z2.),cols{i});
end;
drop i;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Nov 2016 10:24:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-have-the-same-condition/m-p/315139#M68697</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-29T10:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple columns have the same condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-have-the-same-condition/m-p/315150#M68698</link>
      <description>&lt;P&gt;Some questions. &amp;nbsp;Firstly, why are you trying to do this using text numbers? &amp;nbsp;Numeric data types are there for a reason. &amp;nbsp;Secondly, what is the reasoning behind this, newphone would end up looking like:&lt;/P&gt;
&lt;P&gt;0245&lt;/P&gt;
&lt;P&gt;03609&lt;/P&gt;
&lt;P&gt;045907&lt;/P&gt;
&lt;P&gt;Which doesn't really make sense to me. &amp;nbsp;What is col1-col3, it looks from the var name newphone, to be a number, but catting on an 02/03 etc. wouldn't make the result a number. &amp;nbsp;I mean you "could" do:&lt;/P&gt;
&lt;PRE&gt;data have;
  input Acct $ col1 $ col2 $ col3 $;
datalines;
ABC 45 375 89756
TFA 609 8320 835
FGT 5907 561 413
;
run;

data want;
  length newphone $20;
  set have;
  newphone=cats("0",put(lengthn(col1),best.),col1);
run;
&lt;/PRE&gt;
&lt;P&gt;But why?&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2016 11:03:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-have-the-same-condition/m-p/315150#M68698</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-11-29T11:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple columns have the same condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-have-the-same-condition/m-p/315158#M68699</link>
      <description>They are phone numbers. I didnt want to write the whole number because I'm typing on my phone. The whole code is longer than what I wrote here.</description>
      <pubDate>Tue, 29 Nov 2016 11:29:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-have-the-same-condition/m-p/315158#M68699</guid>
      <dc:creator>JT99</dc:creator>
      <dc:date>2016-11-29T11:29:06Z</dc:date>
    </item>
  </channel>
</rss>

