<?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: duplicating observations and creating a new variable/using arrays in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/duplicating-observations-and-creating-a-new-variable-using/m-p/721544#M223665</link>
    <description>Thank you all for the great options, I really appreciate it!</description>
    <pubDate>Wed, 24 Feb 2021 12:31:25 GMT</pubDate>
    <dc:creator>Geoghegan</dc:creator>
    <dc:date>2021-02-24T12:31:25Z</dc:date>
    <item>
      <title>duplicating observations and creating a new variable/using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/duplicating-observations-and-creating-a-new-variable-using/m-p/721443#M223608</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a dataset that has subject IDs as one variable then a few other variables. I need to duplicate those variables and IDs so that I have 5 copies of each. I also need to create a new variable, for example a variable named Color and it has 5 options, Blue, Red, Green, Yellow, and Purple and I need one row for each subject for each color. So it would look something like:&lt;/P&gt;&lt;P&gt;ID Name Date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Color&lt;/P&gt;&lt;P&gt;1&amp;nbsp; Sam&amp;nbsp; &amp;nbsp;1/1/2020&amp;nbsp; &amp;nbsp;Blue&lt;/P&gt;&lt;P&gt;1&amp;nbsp; Sam&amp;nbsp; &amp;nbsp;1/1/2020&amp;nbsp; &amp;nbsp;Red&lt;/P&gt;&lt;P&gt;1&amp;nbsp; Sam&amp;nbsp; &amp;nbsp;1/1/2020&amp;nbsp; &amp;nbsp;Green&lt;/P&gt;&lt;P&gt;1&amp;nbsp; Sam&amp;nbsp; &amp;nbsp;1/1/2020&amp;nbsp; &amp;nbsp;Yellow&lt;/P&gt;&lt;P&gt;1&amp;nbsp; Sam&amp;nbsp; &amp;nbsp;1/1/2020&amp;nbsp; &amp;nbsp;Purple&lt;/P&gt;&lt;P&gt;and then repeat for each other subject and their name and date etc.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought I could do this with an array but I can't figure out how.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was thinking something like:&lt;/P&gt;&lt;P&gt;data new;&lt;/P&gt;&lt;P&gt;set date;&lt;/P&gt;&lt;P&gt;array colors(5) $ Blue $ Red $ Green $ Yellow $ Purple;&lt;/P&gt;&lt;P&gt;do i = 1 to 5;&lt;/P&gt;&lt;P&gt;but I don't know, maybe you can only use a list of variables in arrays and not the values for a variable?&amp;nbsp;&lt;/P&gt;&lt;P&gt;If anyone has ideas on how to do this properly I'd really appreciate it.&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Feb 2021 01:30:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/duplicating-observations-and-creating-a-new-variable-using/m-p/721443#M223608</guid>
      <dc:creator>Geoghegan</dc:creator>
      <dc:date>2021-02-24T01:30:41Z</dc:date>
    </item>
    <item>
      <title>Re: duplicating observations and creating a new variable/using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/duplicating-observations-and-creating-a-new-variable-using/m-p/721454#M223616</link>
      <description>&lt;P&gt;The initial value of array statement is specified in ().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length id 8 name $10 date 8 color $10;
input ID name date DDMMYY10.;
format date DDMMYY10.;
datalines;
1 Sam 1/1/2020
2 Tom 1/2/2020
;
run;

data want(drop=i);
  array acl{5} $10 _temporary_ ('Blue','Red','Green','Yellow','Purple') ;
  set have;
  do i=1 to 5;
    color=acl{i};
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Feb 2021 02:44:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/duplicating-observations-and-creating-a-new-variable-using/m-p/721454#M223616</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-02-24T02:44:09Z</dc:date>
    </item>
    <item>
      <title>Re: duplicating observations and creating a new variable/using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/duplicating-observations-and-creating-a-new-variable-using/m-p/721466#M223624</link>
      <description>&lt;P&gt;You can try the following way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  length id 8 name $10 date 8;
  input ID name date DDMMYY10.;
  format date DDMMYY10.;
datalines;
1 Sam 1/1/2020
2 Tom 1/2/2020
run;

data colors;
  input color $ @@;
  datalines;
Blue Red Green Yellow Purple
run; 
data want;
  set have;
  do i=1 to nobs;
   set colors point=i nobs=nobs;
   output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Feb 2021 04:28:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/duplicating-observations-and-creating-a-new-variable-using/m-p/721466#M223624</guid>
      <dc:creator>LeonCathay</dc:creator>
      <dc:date>2021-02-24T04:28:15Z</dc:date>
    </item>
    <item>
      <title>Re: duplicating observations and creating a new variable/using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/duplicating-observations-and-creating-a-new-variable-using/m-p/721474#M223629</link>
      <description>&lt;P&gt;This is one of those tasks where it's worth remembering the utility of using comma-separated "ranges" in a DO loop:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length id 8 name $10 date 8;
input ID name date DDMMYY10.;
format date DDMMYY10.;
datalines;
1 Sam 1/1/2020
2 Tom 1/2/2020
run;
data want;
  set have ;
  length color $10;
  do color= 'Blue','Red','Green','Yellow','Purple';
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I said comma-separated &lt;EM&gt;&lt;STRONG&gt;ranges&lt;/STRONG&gt;&lt;/EM&gt; instead of comma-separated &lt;EM&gt;&lt;STRONG&gt;values&lt;/STRONG&gt;&lt;/EM&gt;, because constructs like the below are valid when using numeric do loop indexes:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i=1,3,6,9 to 11,15 to 12 by -1,4,2;
   ...
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 24 Feb 2021 04:48:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/duplicating-observations-and-creating-a-new-variable-using/m-p/721474#M223629</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-02-24T04:48:06Z</dc:date>
    </item>
    <item>
      <title>Re: duplicating observations and creating a new variable/using arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/duplicating-observations-and-creating-a-new-variable-using/m-p/721544#M223665</link>
      <description>Thank you all for the great options, I really appreciate it!</description>
      <pubDate>Wed, 24 Feb 2021 12:31:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/duplicating-observations-and-creating-a-new-variable-using/m-p/721544#M223665</guid>
      <dc:creator>Geoghegan</dc:creator>
      <dc:date>2021-02-24T12:31:25Z</dc:date>
    </item>
  </channel>
</rss>

