<?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: Equivalent to rbind under for loop in sas in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Equivalent-to-rbind-under-for-loop-in-sas/m-p/717271#M27489</link>
    <description>&lt;P&gt;&lt;SPAN&gt;To merge two data frames (datasets) horizontally, use the merge() function in the R language. The cbind() function combines R Objects By Rows Or Columns.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The&amp;nbsp;&lt;A href="https://r-lang.com/cbind-in-r/" target="_self"&gt;&lt;STRONG&gt;cbind()&lt;/STRONG&gt;&lt;/A&gt;&amp;nbsp;and&amp;nbsp;&lt;A href="https://r-lang.com/rbind-in-r/" target="_blank" rel="noopener"&gt;&lt;STRONG&gt;rbind()&amp;nbsp;&lt;/STRONG&gt;&lt;/A&gt;functions&amp;nbsp;are generic methods for data frames. These data frame functions will be used if at least one argument is a data frame and the other arguments are vectors or matrices. To merge two data frames (datasets) horizontally, use the&amp;nbsp;&lt;STRONG&gt;merge()&lt;/STRONG&gt;&amp;nbsp;function in the R language.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Loops are the most frequently used snippet in any programming language, and R is no different.&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;All modern programming languages implement special structures that allow the repetition of code instructions.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 06 Feb 2021 09:05:06 GMT</pubDate>
    <dc:creator>KrunalLathiya</dc:creator>
    <dc:date>2021-02-06T09:05:06Z</dc:date>
    <item>
      <title>Equivalent to rbind under for loop in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Equivalent-to-rbind-under-for-loop-in-sas/m-p/530447#M5749</link>
      <description>Hi guys,&lt;BR /&gt;Looking for solution. I want to replicate a code from R to SAS.&lt;BR /&gt;&lt;BR /&gt;Data:&lt;BR /&gt;C1 C2&lt;BR /&gt;A. 10&lt;BR /&gt;B. 20&lt;BR /&gt;A. 40&lt;BR /&gt;C. 5&lt;BR /&gt;B. 55&lt;BR /&gt;&lt;BR /&gt;R code:&lt;BR /&gt;&lt;BR /&gt;Result= data.frame()&lt;BR /&gt;Unq= unique (data$C1)&lt;BR /&gt;&lt;BR /&gt;for( i in Unq)&lt;BR /&gt;{&lt;BR /&gt;i_df=subset ( data, C1==i)&lt;BR /&gt;&lt;BR /&gt;(Some operation)&lt;BR /&gt;Result=rbind (Result, i_df)&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;How to do this by SAS. By using loop, not SQL .&lt;BR /&gt;&lt;BR /&gt;Thanks.</description>
      <pubDate>Sun, 27 Jan 2019 11:02:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Equivalent-to-rbind-under-for-loop-in-sas/m-p/530447#M5749</guid>
      <dc:creator>Souradip</dc:creator>
      <dc:date>2019-01-27T11:02:35Z</dc:date>
    </item>
    <item>
      <title>Re: Equivalent to rbind under for loop in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Equivalent-to-rbind-under-for-loop-in-sas/m-p/530448#M5750</link>
      <description>&lt;P&gt;Hi and welcome to the SAS communities &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since this is a SAS community, not all users are familiar with R syntax. Therefore it is a good idea to show us the desired result from your posted example data.&lt;/P&gt;</description>
      <pubDate>Sun, 27 Jan 2019 11:13:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Equivalent-to-rbind-under-for-loop-in-sas/m-p/530448#M5750</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-27T11:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: Equivalent to rbind under for loop in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Equivalent-to-rbind-under-for-loop-in-sas/m-p/530451#M5751</link>
      <description>&lt;P&gt;If I understood this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by c1;
run;

..(Some operation).....&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 27 Jan 2019 11:50:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Equivalent-to-rbind-under-for-loop-in-sas/m-p/530451#M5751</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-01-27T11:50:31Z</dc:date>
    </item>
    <item>
      <title>Re: Equivalent to rbind under for loop in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Equivalent-to-rbind-under-for-loop-in-sas/m-p/530512#M5755</link>
      <description>You would use BY group processing in SAS not split the data set and combine. Somewhat similar to GROUP_BY in tidyverse but not quite the same. The other approach would be a macro, but I suspect a macro is overkill. &lt;BR /&gt;&lt;BR /&gt;You can probably get it working if you try and do line by line conversion but you’re better off using a SAS optimized approach. &lt;BR /&gt;&lt;BR /&gt;If you explain in more detail perhaps we can help more. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sun, 27 Jan 2019 22:53:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Equivalent-to-rbind-under-for-loop-in-sas/m-p/530512#M5755</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-27T22:53:03Z</dc:date>
    </item>
    <item>
      <title>Re: Equivalent to rbind under for loop in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Equivalent-to-rbind-under-for-loop-in-sas/m-p/530523#M5757</link>
      <description>&lt;P&gt;Since you didn't explain what rbind() does I turned to the trusty Google machine.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="image.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/26612i5F0BBCCA5FBA21BE/image-size/large?v=v2&amp;amp;px=999" role="button" title="image.png" alt="image.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If you want to APPEND a dataset to the end of another dataset then use PROC APPEND.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc append base=result data=i_df ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Jan 2019 01:29:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Equivalent-to-rbind-under-for-loop-in-sas/m-p/530523#M5757</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-01-28T01:29:55Z</dc:date>
    </item>
    <item>
      <title>Re: Equivalent to rbind under for loop in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Equivalent-to-rbind-under-for-loop-in-sas/m-p/530526#M5758</link>
      <description>&lt;P&gt;This paper goes over why this type of approach is not recommended in SAS. As part of that, it starts out with the looping method, which is inefficient in SAS compared to BY groups. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/forum2007/183-2007.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings/proceedings/forum2007/183-2007.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/256445"&gt;@Souradip&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi guys,&lt;BR /&gt;Looking for solution. I want to replicate a code from R to SAS.&lt;BR /&gt;&lt;BR /&gt;Data:&lt;BR /&gt;C1 C2&lt;BR /&gt;A. 10&lt;BR /&gt;B. 20&lt;BR /&gt;A. 40&lt;BR /&gt;C. 5&lt;BR /&gt;B. 55&lt;BR /&gt;&lt;BR /&gt;R code:&lt;BR /&gt;&lt;BR /&gt;Result= data.frame()&lt;BR /&gt;Unq= unique (data$C1)&lt;BR /&gt;&lt;BR /&gt;for( i in Unq)&lt;BR /&gt;{&lt;BR /&gt;i_df=subset ( data, C1==i)&lt;BR /&gt;&lt;BR /&gt;(Some operation)&lt;BR /&gt;Result=rbind (Result, i_df)&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;How to do this by SAS. By using loop, not SQL .&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Jan 2019 01:50:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Equivalent-to-rbind-under-for-loop-in-sas/m-p/530526#M5758</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-28T01:50:00Z</dc:date>
    </item>
    <item>
      <title>Re: Equivalent to rbind under for loop in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Equivalent-to-rbind-under-for-loop-in-sas/m-p/530599#M5766</link>
      <description>Thanks for your comments. Here I create a very simple example for the above. Inputs are&lt;BR /&gt;&lt;BR /&gt;Data 1:&lt;BR /&gt;Year&lt;BR /&gt;2012&lt;BR /&gt;2013&lt;BR /&gt;2014&lt;BR /&gt;&lt;BR /&gt;Data2:&lt;BR /&gt;State year value&lt;BR /&gt;A. 2012. 4&lt;BR /&gt;A. 2013. 6&lt;BR /&gt;B. 2013. 10&lt;BR /&gt;&lt;BR /&gt;Output:&lt;BR /&gt;State. Year. Value&lt;BR /&gt;A. 2012. 4&lt;BR /&gt;A. 2013. 6&lt;BR /&gt;A. 2014. 0&lt;BR /&gt;B. 2012. 0&lt;BR /&gt;B. 2013. 10&lt;BR /&gt;B. 2014. 0&lt;BR /&gt;&lt;BR /&gt;We might have a number of states which might not be possible to execute one by one manually.</description>
      <pubDate>Mon, 28 Jan 2019 12:10:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Equivalent-to-rbind-under-for-loop-in-sas/m-p/530599#M5766</guid>
      <dc:creator>Souradip</dc:creator>
      <dc:date>2019-01-28T12:10:52Z</dc:date>
    </item>
    <item>
      <title>Re: Equivalent to rbind under for loop in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Equivalent-to-rbind-under-for-loop-in-sas/m-p/530782#M5804</link>
      <description>&lt;P&gt;Is your ultimate goal to create a table with all possible values?&lt;/P&gt;
&lt;P&gt;If your table 2 will have at least one value in each group there's an easy fix. If not, the fix is slightly more complex but still relatively easy.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For something like this, a SQL query is pretty robust to work with.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data data1;
do year=2012 to 2014;
output;
end;
run;

data data2;
input state $ year value;
cards;
A 2012 4
A 2013 6
B 2013 10
;;;;
run;

proc sql;
create table want as
select t1.state, t1.year, case when not missing(t2.value) then t2.value else 0 end as newValue
from (select state, year from (select distinct state from data2), (select distinct year from data1)) as t1
left join data2 as t2
on t1.state=t2.state and t1.year=t2.year;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Other options:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. SPARSE with PROC FREQ if every value is present&lt;/P&gt;
&lt;P&gt;2. CLASSDATA&amp;nbsp;option with PROC MEANS or summary proc&lt;/P&gt;
&lt;P&gt;3. PRELOADFMT with a summary proc such as PROC MEANS. That would work here as well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a short video on some of those options, I usually like Option 1, but its not the most robust.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://sasgf16.v.sas.com/detail/videos/breakout-sessions/video/4854738295001/10600---you-can-bet-on-it:-missing-observations-are-preserved-with-the-preloadfmt-and-completetypes" target="_blank"&gt;http://sasgf16.v.sas.com/detail/videos/breakout-sessions/video/4854738295001/10600---you-can-bet-on-it:-missing-observations-are-preserved-with-the-preloadfmt-and-completetypes&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Jan 2019 20:56:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Equivalent-to-rbind-under-for-loop-in-sas/m-p/530782#M5804</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-28T20:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: Equivalent to rbind under for loop in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Equivalent-to-rbind-under-for-loop-in-sas/m-p/530854#M5816</link>
      <description>Thanks. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Tue, 29 Jan 2019 07:19:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Equivalent-to-rbind-under-for-loop-in-sas/m-p/530854#M5816</guid>
      <dc:creator>Souradip</dc:creator>
      <dc:date>2019-01-29T07:19:37Z</dc:date>
    </item>
    <item>
      <title>Re: Equivalent to rbind under for loop in sas</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Equivalent-to-rbind-under-for-loop-in-sas/m-p/717271#M27489</link>
      <description>&lt;P&gt;&lt;SPAN&gt;To merge two data frames (datasets) horizontally, use the merge() function in the R language. The cbind() function combines R Objects By Rows Or Columns.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;The&amp;nbsp;&lt;A href="https://r-lang.com/cbind-in-r/" target="_self"&gt;&lt;STRONG&gt;cbind()&lt;/STRONG&gt;&lt;/A&gt;&amp;nbsp;and&amp;nbsp;&lt;A href="https://r-lang.com/rbind-in-r/" target="_blank" rel="noopener"&gt;&lt;STRONG&gt;rbind()&amp;nbsp;&lt;/STRONG&gt;&lt;/A&gt;functions&amp;nbsp;are generic methods for data frames. These data frame functions will be used if at least one argument is a data frame and the other arguments are vectors or matrices. To merge two data frames (datasets) horizontally, use the&amp;nbsp;&lt;STRONG&gt;merge()&lt;/STRONG&gt;&amp;nbsp;function in the R language.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Loops are the most frequently used snippet in any programming language, and R is no different.&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;All modern programming languages implement special structures that allow the repetition of code instructions.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Feb 2021 09:05:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Equivalent-to-rbind-under-for-loop-in-sas/m-p/717271#M27489</guid>
      <dc:creator>KrunalLathiya</dc:creator>
      <dc:date>2021-02-06T09:05:06Z</dc:date>
    </item>
  </channel>
</rss>

