<?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: How to concatenate different rows? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-different-rows/m-p/871424#M344239</link>
    <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;I currently have a sas data set where each observation has 3 attributes. However, the text input has 5 per row with multiple rows. How do I tell sas to read the first 3 values in the row as an entry, then the next three, etc before moving to the next line? Basically, if one input row looks like this:&lt;/P&gt;&lt;P&gt;4 4 10 2 2 10 5 5 10 6 6 10 9 9 10&lt;/P&gt;&lt;P&gt;I want it to end up like this in the sas dataset:&lt;/P&gt;&lt;P&gt;4 4 10&lt;/P&gt;&lt;P&gt;2 2 10&lt;/P&gt;&lt;P&gt;5 5 10&lt;/P&gt;&lt;P&gt;6 6 10&lt;/P&gt;&lt;P&gt;9 9 10.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Sun, 23 Apr 2023 15:46:29 GMT</pubDate>
    <dc:creator>chaeunwoo</dc:creator>
    <dc:date>2023-04-23T15:46:29Z</dc:date>
    <item>
      <title>How to concatenate different rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-different-rows/m-p/860837#M340048</link>
      <description>&lt;P&gt;I want to make a variable (WANT.VISITS) that lists all the visits (HAVE.VISNO) present in one dataset (HAVE), so that the final dataset (WANT) only has one row per subject.&lt;/P&gt;
&lt;P&gt;Essentially I am trying to make an analysis populations dataset (POP) and want to be able to identify visit-specific exclusions for each subject, e.g. out-of-window visits.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Current Dataset Format*/
data have;
input ID $ VISNO $ RESULT @@;
cards;
A 01 .
A 02 7
A 03 9
A 04 12
A 05 10
B 01 3
B 02 7
B 04 9
B 05 11
C 01 8
C 02 9
C 03 12
;
run;

/*Desired Dataset*/
data want;
input ID $ VISITS @@;
cards;
A 01,02,03,04,05
B 01,02,04,05
C 01,02,03
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Feb 2023 12:53:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-different-rows/m-p/860837#M340048</guid>
      <dc:creator>mariko5797</dc:creator>
      <dc:date>2023-02-25T12:53:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to concatenate different rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-different-rows/m-p/860839#M340049</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/311553"&gt;@mariko5797&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This vill do it, given the input must be sorted in ID and VISNO:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have (drop=RESULT);
  by ID;
  length VISITS $200;
  retain VISITS;
  VISITS = catx(',',VISITS,VISNO);
  if last.ID then do;
    output;
    VISITS = '';
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Feb 2023 13:16:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-different-rows/m-p/860839#M340049</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2023-02-25T13:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to concatenate different rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-different-rows/m-p/870858#M344002</link>
      <description>&lt;P&gt;I believe you can do this by using proc transpose procedure.&lt;/P&gt;&lt;P&gt;1. transpose the dataset by=id and id=visno&lt;/P&gt;&lt;P&gt;2. then concate all visno01-visno0n using catx() function.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this code will help you getting the desired result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc transpose data=have prefix=visits out=tmp;
by id;
id visno;
var visno;
run;

data want;
set tmp;
visits = catx(',', of visits0:);
keep id visits;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2023 18:38:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-different-rows/m-p/870858#M344002</guid>
      <dc:creator>vijaypratap0195</dc:creator>
      <dc:date>2023-04-20T18:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to concatenate different rows?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-different-rows/m-p/871424#M344239</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;I currently have a sas data set where each observation has 3 attributes. However, the text input has 5 per row with multiple rows. How do I tell sas to read the first 3 values in the row as an entry, then the next three, etc before moving to the next line? Basically, if one input row looks like this:&lt;/P&gt;&lt;P&gt;4 4 10 2 2 10 5 5 10 6 6 10 9 9 10&lt;/P&gt;&lt;P&gt;I want it to end up like this in the sas dataset:&lt;/P&gt;&lt;P&gt;4 4 10&lt;/P&gt;&lt;P&gt;2 2 10&lt;/P&gt;&lt;P&gt;5 5 10&lt;/P&gt;&lt;P&gt;6 6 10&lt;/P&gt;&lt;P&gt;9 9 10.&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sun, 23 Apr 2023 15:46:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-concatenate-different-rows/m-p/871424#M344239</guid>
      <dc:creator>chaeunwoo</dc:creator>
      <dc:date>2023-04-23T15:46:29Z</dc:date>
    </item>
  </channel>
</rss>

