<?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: Adding same variables that have the same page number in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-same-variables-that-have-the-same-page-number/m-p/511515#M137664</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;

  input var1 : $8. pg ;
datalines;
subjid   1
usubjid 2
aval      3
subjid  5
;
proc sort data=one;
by var1 pg;
run;

data want;
set one;
by var1;
length want $25;
retain want;
if first.var1 then call missing(want);
want=catx(',',want,pg);
if last.var1;
drop pg;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 08 Nov 2018 19:55:17 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-11-08T19:55:17Z</dc:date>
    <item>
      <title>Adding same variables that have the same page number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-same-variables-that-have-the-same-page-number/m-p/511509#M137659</link>
      <description>&lt;P&gt;data one;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length var1 $8. pg 3.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input var1 pageNum;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;subjid&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;usubjid 2&lt;/P&gt;&lt;P&gt;aval&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;subjid&amp;nbsp; 5&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what I am tryin to do is when var1 is the same it will add the two pageNum together separated by a comma:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;output:&lt;/P&gt;&lt;P&gt;subjid 1,5&lt;/P&gt;&lt;P&gt;usubjid 2&lt;/P&gt;&lt;P&gt;aval&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Nov 2018 19:42:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-same-variables-that-have-the-same-page-number/m-p/511509#M137659</guid>
      <dc:creator>chrissowden</dc:creator>
      <dc:date>2018-11-08T19:42:28Z</dc:date>
    </item>
    <item>
      <title>Re: Adding same variables that have the same page number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-same-variables-that-have-the-same-page-number/m-p/511513#M137662</link>
      <description>&lt;P&gt;do you mean sort and vertical concatentation with delim ','?&lt;/P&gt;</description>
      <pubDate>Thu, 08 Nov 2018 19:49:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-same-variables-that-have-the-same-page-number/m-p/511513#M137662</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-08T19:49:23Z</dc:date>
    </item>
    <item>
      <title>Re: Adding same variables that have the same page number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-same-variables-that-have-the-same-page-number/m-p/511515#M137664</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;

  input var1 : $8. pg ;
datalines;
subjid   1
usubjid 2
aval      3
subjid  5
;
proc sort data=one;
by var1 pg;
run;

data want;
set one;
by var1;
length want $25;
retain want;
if first.var1 then call missing(want);
want=catx(',',want,pg);
if last.var1;
drop pg;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 08 Nov 2018 19:55:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-same-variables-that-have-the-same-page-number/m-p/511515#M137664</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-11-08T19:55:17Z</dc:date>
    </item>
    <item>
      <title>Re: Adding same variables that have the same page number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-same-variables-that-have-the-same-page-number/m-p/511516#M137665</link>
      <description>&lt;P&gt;Here's how I would do it (note the correction of variable name pg to pagenum...)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data one;
  length var1 $8. pagenum 3.;
  input var1 pageNum;
datalines;
subjid   1
usubjid 2
aval      3
subjid  5
;
run;

proc sort data=one;
by var1 pagenum;
run;

data one_output;
set one;
by var1;
attrib pagenums length=$ 20;
retain pagenums first_pagenum;
if first.var1 then do;
   first_pagenum = pagenum;
   call missing(pagenums);
   end;
pagenums = catx(',', pagenums, strip(putn(pagenum, 'best.')));
if last.var1;
keep var1 pagenums first_pagenum;
run;

proc sort data=one_output out=one_output(keep=var1 pagenums);
by first_pagenum var1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I retained the lowest pagenum per var1 (as &lt;EM&gt;first_pagenum&lt;/EM&gt;), so I could sort by that to retain the order in your output dataset.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Extend the length of the character variable&amp;nbsp;&lt;EM&gt;pagenums&lt;/EM&gt; if you have many more references.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Nov 2018 19:58:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-same-variables-that-have-the-same-page-number/m-p/511516#M137665</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2018-11-08T19:58:37Z</dc:date>
    </item>
  </channel>
</rss>

