<?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: Do loop error: The variable X has been already defined in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-The-variable-X-has-been-already-defined/m-p/937645#M368426</link>
    <description>&lt;P&gt;Use GLMSELECT to generate the dummy variables.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2020/08/31/best-generate-dummy-variables-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2020/08/31/best-generate-dummy-variables-sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 30 Jul 2024 17:02:41 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-07-30T17:02:41Z</dc:date>
    <item>
      <title>Do loop error: The variable X has been already defined</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-The-variable-X-has-been-already-defined/m-p/937581#M368394</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;The ICDGRP variable has 52 values. I'm trying to create a dummy variable for each as:&amp;nbsp;&lt;/P&gt;&lt;P&gt;If ICDGRP =1 then ICDGRP1=1; else ICDGRP1 =0;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If ICDGRP =2 then ICDGRP2 =1; else ICDGRP2 =0;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;If ICDGRP =52 then ICDGRP52 =1; else ICDGRP52 =0;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the SAS code below gives me the error of "The variable ICDGRP has been already defined" under the first ICDGRP - here ICDGRP(52).&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data mydata1; 
  set mydata;
  array ICDGRP(52) ICDGRP1-ICDGRP52;
  do i = 1 to 52;
  If ICDGRP(i) = (i) then ICDGRP(i) = 1; else ICDGRP(i)=0; 

  end;
run; 

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;: "The variable ICDGRP has been already defined"&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2024 12:22:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-The-variable-X-has-been-already-defined/m-p/937581#M368394</guid>
      <dc:creator>altadata1</dc:creator>
      <dc:date>2024-07-30T12:22:03Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop error: The variable X has been already defined</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-The-variable-X-has-been-already-defined/m-p/937584#M368397</link>
      <description>&lt;P&gt;You cannot have an array name that is the same as a variable name. Obviously there is a variable named ICDGRP in data set MYDATA.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Which brings us to a bigger point. Why create all these dummy variables in the first place? Dummy variables are rarely needed in SAS, because most SAS analysis procedures can easily create their own dummy variables behind the scenes without you having to write program code to create the dummy variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So what is the purpose of creating dummy variables here? What analyses/reports/tables would you create once you have these dummy variables?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2024 12:28:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-The-variable-X-has-been-already-defined/m-p/937584#M368397</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-07-30T12:28:56Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop error: The variable X has been already defined</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-The-variable-X-has-been-already-defined/m-p/937586#M368399</link>
      <description>&lt;P&gt;Thank you for the reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm estimating a ratio classified by ICDGRP in SUDAAN (Proc ratio). For that, I need to create dummy variable for each value of ICDGRP.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2024 12:33:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-The-variable-X-has-been-already-defined/m-p/937586#M368399</guid>
      <dc:creator>altadata1</dc:creator>
      <dc:date>2024-07-30T12:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop error: The variable X has been already defined</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-The-variable-X-has-been-already-defined/m-p/937588#M368401</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;I need to create dummy variable for each value of ICDGRP.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That would mean this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mydata1; 
  set mydata;
  array _ICDGRP(52) ICDGRP1-ICDGRP52;
  do I = 1 to 52;
    if ICDGRP = I then _ICDGRP(I) = 1; else _ICDGRP(I)=0; 
    ...
  end;
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note the array name. It is different from the variable name you already have.&lt;/P&gt;
&lt;P&gt;Also note that the test:&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;if ICDGRP = I then _ICDGRP(I) = 1; else _ICDGRP(I)=0;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;can be written as:&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;  _ICDGRP(I) = (ICDGRP = I) ; &lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;Edited: Added missing underscores in test statement. &lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2024 13:21:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-The-variable-X-has-been-already-defined/m-p/937588#M368401</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2024-07-30T13:21:45Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop error: The variable X has been already defined</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-The-variable-X-has-been-already-defined/m-p/937593#M368405</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you mean&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if ICDGRP = I then _ICDGRP(I) = 1; else _ICDGRP(I)=0; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;note the underscores in the array name&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2024 13:14:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-The-variable-X-has-been-already-defined/m-p/937593#M368405</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-07-30T13:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop error: The variable X has been already defined</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-The-variable-X-has-been-already-defined/m-p/937595#M368406</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do indeed. Thank you for the correction. &lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2024 13:19:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-The-variable-X-has-been-already-defined/m-p/937595#M368406</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2024-07-30T13:19:11Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop error: The variable X has been already defined</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-The-variable-X-has-been-already-defined/m-p/937645#M368426</link>
      <description>&lt;P&gt;Use GLMSELECT to generate the dummy variables.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2020/08/31/best-generate-dummy-variables-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2020/08/31/best-generate-dummy-variables-sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jul 2024 17:02:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Do-loop-error-The-variable-X-has-been-already-defined/m-p/937645#M368426</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-07-30T17:02:41Z</dc:date>
    </item>
  </channel>
</rss>

