<?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: Array: variables numeric and character start same in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Array-variables-numeric-and-character-start-same/m-p/508776#M136688</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;
&lt;P&gt;I don't know if this is an official "maxim" or not, but PROC CONTENTS is a programmer’s best friend.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Actually, proc contents is part of Maxim 3 (know your data) &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 30 Oct 2018 15:57:14 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-10-30T15:57:14Z</dc:date>
    <item>
      <title>Array: variables numeric and character start same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-variables-numeric-and-character-start-same/m-p/508701#M136665</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;I want to remove certain symbols from this list of variables ST2--bsitosrat, and also to rename them into bm1--bm44, so I write this to code. &amp;nbsp;Problem is array a will not run because it states ST2--bsitosrat contains both numeric and character variables. &amp;nbsp;Can you suggest a way to do this? &amp;nbsp;The dataset keep renewing and the numeric or character status of the list change over time which to me is the challenge. &amp;nbsp;thanks&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;array&lt;/SPAN&gt; a[*]&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ST2 Tchol LPA LPA_mass HCY CYST_C &amp;nbsp;eGFR bsitos bsitosrat;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;array&lt;/SPAN&gt; b[*]&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;bm1 &amp;nbsp;bm2 &amp;nbsp;bm3 &amp;nbsp;bm4 &amp;nbsp;bm5 &amp;nbsp;bm6 &amp;nbsp;bm7. bm8. bm9;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;do&lt;/SPAN&gt; i = &lt;SPAN&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN&gt;to&lt;/SPAN&gt; dim(b);&lt;/P&gt;
&lt;P&gt;a[i]=compress(a[i], &lt;SPAN&gt;"&amp;lt;&amp;gt;"&lt;/SPAN&gt;);&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if&lt;/SPAN&gt; a[i] in (&lt;SPAN&gt;"See Notes"&lt;/SPAN&gt;, &lt;SPAN&gt;"Rej"&lt;/SPAN&gt;) &lt;SPAN&gt;then&lt;/SPAN&gt; a[i]=&lt;SPAN&gt;&lt;STRONG&gt;.&lt;/STRONG&gt;&lt;/SPAN&gt;;&lt;/P&gt;
&lt;P&gt;b[i]=&lt;SPAN&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;*a[i];&lt;SPAN class="Apple-converted-space"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;end&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 14:17:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-variables-numeric-and-character-start-same/m-p/508701#M136665</guid>
      <dc:creator>rykwong</dc:creator>
      <dc:date>2018-10-30T14:17:46Z</dc:date>
    </item>
    <item>
      <title>Re: Array: variables numeric and character start same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-variables-numeric-and-character-start-same/m-p/508705#M136669</link>
      <description>&lt;P&gt;Numeric variables won't contain the symbols that you are trying to remove, so you don't even need to run this code on the numeric variables; just run it on the character variables.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 14:20:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-variables-numeric-and-character-start-same/m-p/508705#M136669</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-10-30T14:20:41Z</dc:date>
    </item>
    <item>
      <title>Re: Array: variables numeric and character start same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-variables-numeric-and-character-start-same/m-p/508707#M136670</link>
      <description>Thanks but the problem is the dataset changes all the time and some variables on the list contains the symbols next week when they do not now.  Some variables contains the symbols (thus character) now and may no long contain the symbol (i.e. because numeric)&lt;BR /&gt;I am trying to create a code that works over time&lt;BR /&gt;</description>
      <pubDate>Tue, 30 Oct 2018 14:26:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-variables-numeric-and-character-start-same/m-p/508707#M136670</guid>
      <dc:creator>rykwong</dc:creator>
      <dc:date>2018-10-30T14:26:44Z</dc:date>
    </item>
    <item>
      <title>Re: Array: variables numeric and character start same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-variables-numeric-and-character-start-same/m-p/508709#M136671</link>
      <description>&lt;P&gt;the list of variables is actually much larger and I am numeric vs character status changes week by week&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 14:28:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-variables-numeric-and-character-start-same/m-p/508709#M136671</guid>
      <dc:creator>rykwong</dc:creator>
      <dc:date>2018-10-30T14:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: Array: variables numeric and character start same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-variables-numeric-and-character-start-same/m-p/508713#M136672</link>
      <description>&lt;P&gt;Then you can use PROC CONTENTS to determine which variables are numeric (denoted as TYPE=1 by PROC CONTENTS) and which variables are character (denoted as TYPE=2 by PROC CONTENTS).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=have out=_contents_ noprint;
run;

proc sql noprint;
      select distinct name into :charvars separated by ' ' from _contents_ where type=2;
quit;

data want;
    set have;
    array a &amp;amp;varnames;
    array b bm1-bm&amp;amp;sqlobs;
    do i=1 to &amp;amp;sqlobs;
         /* some stuff here */
    end;
run;
    &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I don't know if this is an official "maxim" or not, but PROC CONTENTS is a programmer’s best friend.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 14:37:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-variables-numeric-and-character-start-same/m-p/508713#M136672</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-10-30T14:37:23Z</dc:date>
    </item>
    <item>
      <title>Re: Array: variables numeric and character start same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-variables-numeric-and-character-start-same/m-p/508714#M136673</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;Thanks but the problem is the dataset changes all the time&amp;nbsp;" - and that is indeed the sole root of your problem, thus fixing that should be highest priority.&amp;nbsp; Unless you like refactoring each and every run, in which case just do it manually.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 14:35:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-variables-numeric-and-character-start-same/m-p/508714#M136673</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-30T14:35:49Z</dc:date>
    </item>
    <item>
      <title>Re: Array: variables numeric and character start same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-variables-numeric-and-character-start-same/m-p/508715#M136674</link>
      <description>&lt;P&gt;Some sample data would help test&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 14:41:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-variables-numeric-and-character-start-same/m-p/508715#M136674</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-10-30T14:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: Array: variables numeric and character start same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-variables-numeric-and-character-start-same/m-p/508726#M136680</link>
      <description>&lt;P&gt;As you can't define numeric and character variables in same array and special symbol are not expected in numeric&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you can:&lt;/P&gt;
&lt;P&gt;1)&amp;nbsp;create a new dataset and rename variable using proc dataset.&lt;/P&gt;
&lt;P&gt;2) define array of character variables only:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
  set have;  
  array a _character_;
  do i=1 to dim(a);
      a(i) = compress(a(i), '&amp;lt;&amp;gt;');
      if a(i) in ("See Notes" , "Rej") then a(i) = . ;
  end;
run;

proc datasets lib=work;
   modify new;
   rename 
      'ST2'   = 'BM1'
      'TCHOL' = 'BM2'
      'LPA'  =  'BM3'
       .....
  ;
quit;
      &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 14:55:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-variables-numeric-and-character-start-same/m-p/508726#M136680</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-10-30T14:55:27Z</dc:date>
    </item>
    <item>
      <title>Re: Array: variables numeric and character start same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-variables-numeric-and-character-start-same/m-p/508729#M136681</link>
      <description>This is a problem with your input data. I'm guessing you're reading from an excel file. The variable types in an array must be the same type, so you'll first need to conver tthem all to the same type. In your code some have periods but they shouldn't.</description>
      <pubDate>Tue, 30 Oct 2018 14:55:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-variables-numeric-and-character-start-same/m-p/508729#M136681</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-10-30T14:55:16Z</dc:date>
    </item>
    <item>
      <title>Re: Array: variables numeric and character start same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-variables-numeric-and-character-start-same/m-p/508774#M136687</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16220"&gt;@rykwong&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;The dataset keep renewing and the numeric or character status of the list change over time which to me is the challenge.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Translation: I'm wading hip-deep in a pile of excrements, and it STINKS!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Fix the import process, so you get consistent attributes.&lt;/P&gt;
&lt;P&gt;DO NOT USE EXCEL, period. If data has to come from an Excel source, save it to a csv file and read that with a data step.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 15:55:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-variables-numeric-and-character-start-same/m-p/508774#M136687</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-30T15:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: Array: variables numeric and character start same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Array-variables-numeric-and-character-start-same/m-p/508776#M136688</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;
&lt;P&gt;I don't know if this is an official "maxim" or not, but PROC CONTENTS is a programmer’s best friend.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Actually, proc contents is part of Maxim 3 (know your data) &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 15:57:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Array-variables-numeric-and-character-start-same/m-p/508776#M136688</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-30T15:57:14Z</dc:date>
    </item>
  </channel>
</rss>

