<?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: Concatenating cross observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-cross-observations/m-p/40027#M8104</link>
    <description>Thank you so much!&lt;BR /&gt;
I went back and revised my code. It's less clumsy now. You introduced the MOD function to me :).&lt;BR /&gt;
I've signed up for the SAS SQL training so I will review your code after that study...&lt;BR /&gt;
&lt;BR /&gt;
data work.NameList;&lt;BR /&gt;
	set sasuser.pilots(keep=lastname)End=last ;&lt;BR /&gt;
	Length GroupList $ 500;&lt;BR /&gt;
	retain GroupList;&lt;BR /&gt;
	Grouplist=Catx(';',Grouplist,LastName);&lt;BR /&gt;
	if mod(_n_,5)=0 then do;&lt;BR /&gt;
		output;&lt;BR /&gt;
		GroupList='';&lt;BR /&gt;
	end;&lt;BR /&gt;
	else if last=1 then output;&lt;BR /&gt;
	drop lastname;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print data=work.namelist;&lt;BR /&gt;
run;</description>
    <pubDate>Tue, 29 Mar 2011 23:04:17 GMT</pubDate>
    <dc:creator>mnew</dc:creator>
    <dc:date>2011-03-29T23:04:17Z</dc:date>
    <item>
      <title>Concatenating cross observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-cross-observations/m-p/40025#M8102</link>
      <description>Experts:&lt;BR /&gt;
&lt;BR /&gt;
Another beginner question. How do you use the values in different observations as arguments for a function? I'm trying to concatenate string values from multiple observations. I'll use the sasuser.pilots as an example. Each observation has a person's name etc. What if you need to generate name lists so you can assign these people to teams of five?&lt;BR /&gt;
&lt;BR /&gt;
Here's very clumsy code I managed to come up with. I'm sure it is not the way to go because if the dataset has hundreds of people, I would be in real misery :). Maybe my trouble is also not knowing how to use a do loop here.&lt;BR /&gt;
&lt;BR /&gt;
Thank you for your time in advance.&lt;BR /&gt;
&lt;BR /&gt;
data work.NameList;&lt;BR /&gt;
	set sasuser.pilots(keep=lastname)End=last ;&lt;BR /&gt;
	Length GroupList $ 500;&lt;BR /&gt;
	retain GroupList;&lt;BR /&gt;
	if _n_ &amp;lt; 11 then do;&lt;BR /&gt;
	Counter+1;&lt;BR /&gt;
	Grouplist=Catx(';',Grouplist,LastName);&lt;BR /&gt;
	if _n_=10 then do;&lt;BR /&gt;
		output;&lt;BR /&gt;
		GroupList='';&lt;BR /&gt;
		Counter=0;&lt;BR /&gt;
		end;&lt;BR /&gt;
	end;&lt;BR /&gt;
if 11 &amp;lt;=_n_&amp;lt;=15 then do;&lt;BR /&gt;
Counter+1;&lt;BR /&gt;
	Grouplist=Catx(';',Grouplist,LastName);&lt;BR /&gt;
	if _n_=15 then do;&lt;BR /&gt;
		output;&lt;BR /&gt;
		GroupList='';&lt;BR /&gt;
		Counter=0;&lt;BR /&gt;
		end;&lt;BR /&gt;
	end;&lt;BR /&gt;
if _n_&amp;gt;15 then do;&lt;BR /&gt;
	Counter+1;&lt;BR /&gt;
	Grouplist=Catx(';',Grouplist,LastName);&lt;BR /&gt;
	if last=1 then output;&lt;BR /&gt;
	end;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print data=work.namelist;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 29 Mar 2011 17:43:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-cross-observations/m-p/40025#M8102</guid>
      <dc:creator>mnew</dc:creator>
      <dc:date>2011-03-29T17:43:59Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating cross observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-cross-observations/m-p/40026#M8103</link>
      <description>Hello Mnew,&lt;BR /&gt;
&lt;BR /&gt;
This is a possible solution. It could be much easier if you need only team number.&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc SQL;&lt;BR /&gt;
  create table n as&lt;BR /&gt;
  select distinct name as name from sashelp.class&lt;BR /&gt;
;quit;&lt;BR /&gt;
data g;&lt;BR /&gt;
  length team $100;&lt;BR /&gt;
  retain team;&lt;BR /&gt;
  set n;&lt;BR /&gt;
  if _n_=1 then team="";&lt;BR /&gt;
  if MOD(_n_-1,5) = 0 then do; g+1; team=""; end;&lt;BR /&gt;
  team=TRIM(team)||TRIM(name)||";";&lt;BR /&gt;
run;&lt;BR /&gt;
proc SQL;&lt;BR /&gt;
  create table g1 as&lt;BR /&gt;
  select a.name,a.g,b.team &lt;BR /&gt;
  from g as a left join (select g, max(team) as team from g group by g) as b&lt;BR /&gt;
  on a.g=b.g&lt;BR /&gt;
;quit;&lt;BR /&gt;
proc SQL;&lt;BR /&gt;
  create table r as&lt;BR /&gt;
  select a.*, b.g, b.team &lt;BR /&gt;
  from sashelp.class as a left join g1 as b on a.name=b.name&lt;BR /&gt;
;quit;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
Sincerely,&lt;BR /&gt;
SPR</description>
      <pubDate>Tue, 29 Mar 2011 18:17:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-cross-observations/m-p/40026#M8103</guid>
      <dc:creator>SPR</dc:creator>
      <dc:date>2011-03-29T18:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating cross observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Concatenating-cross-observations/m-p/40027#M8104</link>
      <description>Thank you so much!&lt;BR /&gt;
I went back and revised my code. It's less clumsy now. You introduced the MOD function to me :).&lt;BR /&gt;
I've signed up for the SAS SQL training so I will review your code after that study...&lt;BR /&gt;
&lt;BR /&gt;
data work.NameList;&lt;BR /&gt;
	set sasuser.pilots(keep=lastname)End=last ;&lt;BR /&gt;
	Length GroupList $ 500;&lt;BR /&gt;
	retain GroupList;&lt;BR /&gt;
	Grouplist=Catx(';',Grouplist,LastName);&lt;BR /&gt;
	if mod(_n_,5)=0 then do;&lt;BR /&gt;
		output;&lt;BR /&gt;
		GroupList='';&lt;BR /&gt;
	end;&lt;BR /&gt;
	else if last=1 then output;&lt;BR /&gt;
	drop lastname;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print data=work.namelist;&lt;BR /&gt;
run;</description>
      <pubDate>Tue, 29 Mar 2011 23:04:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Concatenating-cross-observations/m-p/40027#M8104</guid>
      <dc:creator>mnew</dc:creator>
      <dc:date>2011-03-29T23:04:17Z</dc:date>
    </item>
  </channel>
</rss>

