<?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: Repeating Values in New Column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Repeating-Values-in-New-Column/m-p/583018#M165919</link>
    <description>&lt;P&gt;I would probably provide the number and repeats in a data set and then use SAS to expand it and merge it in.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would need to modify the lines in the data repeat data set.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data repeat;
input number times;
do i=1 to times;
output;
end;
cards;
1 3
2 2
3 4
;;;;

data want;
merge have repeat;
run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 21 Aug 2019 21:35:37 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-08-21T21:35:37Z</dc:date>
    <item>
      <title>Repeating Values in New Column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeating-Values-in-New-Column/m-p/583013#M165914</link>
      <description>&lt;P&gt;Hi All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to create a SAS data set which already has two columns with various data, what I need is to create another column which repeats certain numbers (that I can specify) and these repeat a certain number of time (which I can specify).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For Example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Column A &amp;amp; B denotes random data, looking for a way to create column C&lt;/LI&gt;&lt;LI&gt;Repeat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TD&gt;&lt;TD&gt;&lt;P&gt;8769&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;3&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;13135&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;345&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;3&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;45647&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;45345&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;3&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;65923&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;345353&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;3&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to be able to specify the number I see in column C (i.e. 1,2,3) as well as the number of times I want them to appear (i.e. 1 to appear 3 times, 2 to appear 2 times and 3 to appear 4 times)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So essentially repeating values in a new column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is much appreciated&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2019 21:15:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeating-Values-in-New-Column/m-p/583013#M165914</guid>
      <dc:creator>SNG1</dc:creator>
      <dc:date>2019-08-21T21:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: Repeating Values in New Column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeating-Values-in-New-Column/m-p/583018#M165919</link>
      <description>&lt;P&gt;I would probably provide the number and repeats in a data set and then use SAS to expand it and merge it in.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would need to modify the lines in the data repeat data set.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data repeat;
input number times;
do i=1 to times;
output;
end;
cards;
1 3
2 2
3 4
;;;;

data want;
merge have repeat;
run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Aug 2019 21:35:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeating-Values-in-New-Column/m-p/583018#M165919</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-08-21T21:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: Repeating Values in New Column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeating-Values-in-New-Column/m-p/583027#M165927</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/238046"&gt;@SNG1&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;If I understand your spec correctly (and it's a big IF), you could do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;           
  input A B ;         
  cards ;             
    3456    234       
 4563456   3566       
  456456 145345       
    6876   7567       
    3554 345435       
   32454   8769       
   13135    345       
   45647  45345       
   65923 345353       
run ;                 
                      
data spec (keep = C) ;
  input C N ;         
  do _n_ = 1 to N ;   
    output ;          
  end ;               
  cards ;             
1 3                   
2 2                   
3 4                   
run ;                 
                      
data want  ;          
  merge have spec ;   
run ;                 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If your spec is not exhaustive - i.e., the total of N in SPEC is less than the number of records in HAVE , - the non-covered slack of the output records will receive a missing value for C.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, you can provide a spec using an array and do it this way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;                           
  array spec [3] _temporary_ (3 2 4) ;
  do C = 1 to dim (spec) ;            
    do _n_ = 1 to spec [C] ;          
      set have ;                      
      output ;                        
    end ;                             
  end ;                               
run ;                                 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, it works a&amp;nbsp; bit differently if your spec is not exhaustive: Instead of padding the non-covered slack with C=., once the spec values have been used up, it will start assigning C using the same spec from the first item on. It can be viewed as an advantage or not be desirable - depending on what you need to do in the case of non-exhaustive spec.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Aug 2019 22:46:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeating-Values-in-New-Column/m-p/583027#M165927</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-08-21T22:46:07Z</dc:date>
    </item>
    <item>
      <title>Re: Repeating Values in New Column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeating-Values-in-New-Column/m-p/583145#M165977</link>
      <description>&lt;P&gt;Thanks a Lot for the Replies both&lt;/P&gt;</description>
      <pubDate>Thu, 22 Aug 2019 12:29:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeating-Values-in-New-Column/m-p/583145#M165977</guid>
      <dc:creator>SNG1</dc:creator>
      <dc:date>2019-08-22T12:29:35Z</dc:date>
    </item>
  </channel>
</rss>

