<?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 do I define an array as numeric or character? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-define-an-array-as-numeric-or-character/m-p/284718#M58102</link>
    <description>I see that you use a format of TREAT_NOF, but that is not what you have in your PROC FORMAT statement. It also looks like TREAT1-TREAT4 are coming from your work.project2 data? Or are you creating them. If they are character variables in work.project2, then you cannot format them with a numeric format. &lt;BR /&gt;&lt;BR /&gt;Just curious.&lt;BR /&gt;&lt;BR /&gt;cynthia</description>
    <pubDate>Fri, 15 Jul 2016 01:27:59 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2016-07-15T01:27:59Z</dc:date>
    <item>
      <title>How do I define an array as numeric or character?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-define-an-array-as-numeric-or-character/m-p/284707#M58097</link>
      <description>&lt;P&gt;I'm trying to make an array, here's my coding:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;options nodate nonumber&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN&gt;&lt;STRONG&gt;import&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN&gt;out&lt;/SPAN&gt; = project2&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;datafile&lt;/SPAN&gt;&lt;SPAN&gt;= &lt;/SPAN&gt;"\\Client\H$\Desktop\project2.xlsx"&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;dbms&lt;/SPAN&gt;= XLSX replace;&lt;/P&gt;&lt;P&gt;get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&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN&gt;&lt;STRONG&gt;print&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN&gt;data&lt;/SPAN&gt;=project2;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/SPAN&gt; temp1;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;array&lt;/SPAN&gt; treatment[&lt;SPAN&gt;&lt;STRONG&gt;4&lt;/STRONG&gt;&lt;/SPAN&gt;] treat1-treat4;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;retain&lt;/SPAN&gt; treat1-treat4;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;set&lt;/SPAN&gt; project2;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;by&lt;/SPAN&gt; id;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;if&lt;/SPAN&gt; first.id &lt;SPAN&gt;then&lt;/SPAN&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; &lt;SPAN&gt;&lt;STRONG&gt;4&lt;/STRONG&gt;&lt;/SPAN&gt;;&amp;nbsp;&lt;/P&gt;&lt;P&gt;treatment[i]=&lt;SPAN&gt;&lt;STRONG&gt;.&lt;/STRONG&gt;&lt;/SPAN&gt;;&amp;nbsp;&lt;/P&gt;&lt;P&gt;end&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;treatment[treat_no] = treat_no;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if&lt;SPAN&gt; last.id &lt;/SPAN&gt;then output&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;format&lt;/SPAN&gt; treat1-treat4 &lt;SPAN&gt;treat_nof.&lt;/SPAN&gt;;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;keep&lt;/SPAN&gt; id treat1-treat4;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN&gt;&lt;STRONG&gt;print&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN&gt;data&lt;/SPAN&gt;=temp1;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; id treat1-treat4;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;When I put this into SAS it comes back with the following errors:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Variable treatment has been defined as both character and numeric.&lt;/P&gt;&lt;P&gt;ERROR 48-59: The format TREAT_NOF was not found or could not be loaded.&lt;/P&gt;&lt;P&gt;ERROR: Variable TREAT1 not found. (following the 'var treat1-treat4' statement).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm wondering if someone can kindly advise me on how to fix these errors?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2016 00:06:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-define-an-array-as-numeric-or-character/m-p/284707#M58097</guid>
      <dc:creator>boodaloo1</dc:creator>
      <dc:date>2016-07-15T00:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do I define an array as numeric or character?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-define-an-array-as-numeric-or-character/m-p/284716#M58101</link>
      <description>&lt;P&gt;ERROR: Variable treatment has been defined as both character and numeric.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;array&lt;/SPAN&gt;&lt;SPAN&gt; treatment[&lt;/SPAN&gt;&lt;SPAN&gt;&lt;STRONG&gt;4&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt;] treat1-treat4;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;--&amp;gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;array&lt;SPAN&gt;&amp;nbsp;_treatment[&lt;/SPAN&gt;&lt;SPAN&gt;&lt;STRONG&gt;4&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN&gt;] treat1-treat4;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;also change your array name into&amp;nbsp;_treatment in the following code.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR 48-59: The format TREAT_NOF was not found or could not be loaded.&lt;/P&gt;
&lt;P&gt;Your format name is&amp;nbsp;&lt;SPAN&gt;treat_no &amp;nbsp;NOT&amp;nbsp;treat_nof&lt;/SPAN&gt;&lt;/P&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>Fri, 15 Jul 2016 01:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-define-an-array-as-numeric-or-character/m-p/284716#M58101</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-15T01:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do I define an array as numeric or character?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-define-an-array-as-numeric-or-character/m-p/284718#M58102</link>
      <description>I see that you use a format of TREAT_NOF, but that is not what you have in your PROC FORMAT statement. It also looks like TREAT1-TREAT4 are coming from your work.project2 data? Or are you creating them. If they are character variables in work.project2, then you cannot format them with a numeric format. &lt;BR /&gt;&lt;BR /&gt;Just curious.&lt;BR /&gt;&lt;BR /&gt;cynthia</description>
      <pubDate>Fri, 15 Jul 2016 01:27:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-define-an-array-as-numeric-or-character/m-p/284718#M58102</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2016-07-15T01:27:59Z</dc:date>
    </item>
    <item>
      <title>Re: How do I define an array as numeric or character?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-define-an-array-as-numeric-or-character/m-p/284719#M58103</link>
      <description>&lt;P&gt;Cynthia,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm attempting to create the TREAT1-TREAT4.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2016 01:31:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-define-an-array-as-numeric-or-character/m-p/284719#M58103</guid>
      <dc:creator>boodaloo1</dc:creator>
      <dc:date>2016-07-15T01:31:36Z</dc:date>
    </item>
    <item>
      <title>Re: How do I define an array as numeric or character?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-define-an-array-as-numeric-or-character/m-p/284720#M58104</link>
      <description>&lt;P&gt;By any chance, does your data set PROJECT2 contain a character variable named TREATMENT? &amp;nbsp;That would conflict with an array called TREATMENT, containing numeric elements.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2016 01:33:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-define-an-array-as-numeric-or-character/m-p/284720#M58104</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-07-15T01:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I define an array as numeric or character?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-define-an-array-as-numeric-or-character/m-p/284721#M58105</link>
      <description>&lt;P&gt;I wish it did! That would be a quick, logical fix. It contains a variable named treat_no, but not treatment.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2016 01:34:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-define-an-array-as-numeric-or-character/m-p/284721#M58105</guid>
      <dc:creator>boodaloo1</dc:creator>
      <dc:date>2016-07-15T01:34:59Z</dc:date>
    </item>
    <item>
      <title>Re: How do I define an array as numeric or character?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-define-an-array-as-numeric-or-character/m-p/284725#M58107</link>
      <description>&lt;P&gt;First up: the format issue - you defined a format name "TREAT_NO" but are trying to apply a format name "TREAT_NOF".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The answer to your headline question: How to define an array as numeric or character: When defining the array, after declaring the number of elements, the inclusion/exclustion of $ will determine if the array is character or numeric. Naturally a character array should only reference character variables, and a numeric array numeric variables. So:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;array TestNums[4] Num1-Num4; /* Numeric array */&lt;/P&gt;&lt;P&gt;array TestChars[4] $ Char1-Char4; /* Character aray */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When the array is declared, if the "associated variables" do not yet exist in the PDV, the array statement will create them. If you do not include any "associated variables", then a sequence of variables with a prefix of the array name will be created. So:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;array Dummy[10]; /* Will create numeric varables Dummy1, Dummy2, etc, up to Dummy 10 so that each array element can reference the relevant variable */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your errors would be easier to diagnose if we knew the structure of the source data set WORK.PROJECT2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would suggest:&lt;/P&gt;&lt;P&gt;- place the ARRAY &amp;amp; RETAIN statements AFTER the SET statements, so that the array references existing variables, rather than creating them.&lt;/P&gt;&lt;P&gt;- if still failing, please post a PROC CONTENTS of the WORK.PROJECT2 data set so we are aware of all variables in the source data.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2016 01:50:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-define-an-array-as-numeric-or-character/m-p/284725#M58107</guid>
      <dc:creator>AndrewHowell</dc:creator>
      <dc:date>2016-07-15T01:50:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do I define an array as numeric or character?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-define-an-array-as-numeric-or-character/m-p/284734#M58110</link>
      <description>&lt;P&gt;What values do you want to see in treat1-treat4?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2016 02:50:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-define-an-array-as-numeric-or-character/m-p/284734#M58110</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-15T02:50:04Z</dc:date>
    </item>
    <item>
      <title>Re: How do I define an array as numeric or character?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-define-an-array-as-numeric-or-character/m-p/506693#M135822</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/73231"&gt;@boodaloo1&lt;/a&gt;&amp;nbsp;- do you require any further assistance with this question? If not, if any of the responses were useful, can you please&amp;nbsp;select one as the solution to your question? Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Oct 2018 22:17:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-define-an-array-as-numeric-or-character/m-p/506693#M135822</guid>
      <dc:creator>AndrewHowell</dc:creator>
      <dc:date>2018-10-22T22:17:26Z</dc:date>
    </item>
  </channel>
</rss>

