<?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: PROC SQL to concatenate distinct number and associated text in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-to-concatenate-distinct-number-and-associated-text/m-p/528500#M144252</link>
    <description>AFAIK you cannot easily do that in SQL. You’ll have to change to a data step.</description>
    <pubDate>Sat, 19 Jan 2019 05:35:35 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-01-19T05:35:35Z</dc:date>
    <item>
      <title>PROC SQL to concatenate distinct number and associated text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-to-concatenate-distinct-number-and-associated-text/m-p/528479#M144241</link>
      <description>&lt;P&gt;I need to combine reasons from my dataset to look like these for the ones in the table that have a reason/cause. I have completed the programming part to create the table, but I don't know how to append the reason/cause to the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table table as&lt;BR /&gt; &lt;BR /&gt;select distinct &lt;BR /&gt;1 as no,&lt;BR /&gt;'Enrolled' as descrip,&lt;BR /&gt;put(count(case when enrolled=1 then 1 else . end),2.) as count&lt;BR /&gt;from enrolled&lt;/P&gt;
&lt;P&gt;union&lt;BR /&gt;select distinct &lt;BR /&gt;2 as no,&lt;BR /&gt;'Treated' as descrip,&lt;BR /&gt;put(count(case when treated=1 then 1 else . end),2.) as count&lt;BR /&gt;from treated&lt;/P&gt;
&lt;P&gt;union&lt;BR /&gt;select distinct &lt;BR /&gt;3 as no,&lt;BR /&gt;'Off-study prior to receiving therapy' as descrip,&lt;BR /&gt;put(count(case when offstudy_pre_trt=1 then 1 else . end),2.) as count&lt;BR /&gt;from offstudy_pre_trt&lt;/P&gt;
&lt;P&gt;union&lt;BR /&gt;select distinct &lt;BR /&gt;4 as no,&lt;BR /&gt;'On-study, Active' as descrip,&lt;BR /&gt;put(count(case when off_study=0 then 1 else . end),2.) as count&lt;BR /&gt;from on_study&lt;BR /&gt; &lt;BR /&gt;union&lt;BR /&gt;select distinct &lt;BR /&gt;5 as no,&lt;BR /&gt;'On-study, LTFU' as descrip,&lt;BR /&gt;put(count(case when ltfu=1 then 1 else . end),2.) as count&lt;BR /&gt;from ltfu&lt;/P&gt;
&lt;P&gt;union&lt;BR /&gt;select distinct&lt;BR /&gt;6 as no,&lt;BR /&gt;'Deaths on study and cause of death' as descrip,&lt;BR /&gt;put(count(case when death_onstudy=1 then 1 else . end),2.) as count&lt;BR /&gt;from on_study&lt;/P&gt;
&lt;P&gt;union&lt;BR /&gt;select distinct&lt;BR /&gt;7 as no,&lt;BR /&gt;'Off-study and reason' as descrip,&lt;BR /&gt;put(count(case when off_study=1 then 1 else . end),2.) as count&lt;BR /&gt;from on_study&lt;/P&gt;
&lt;P&gt;order by no;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For #6 and #7, please tell me how to append the associated reason.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is how the table should look:&lt;/P&gt;
&lt;TABLE width="538"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="274"&gt;
&lt;P&gt;Category&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="264"&gt;
&lt;P&gt;Number of Subjects&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="274"&gt;
&lt;P&gt;Enrolled&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="264"&gt;
&lt;P&gt;abc&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="274"&gt;
&lt;P&gt;Treated&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="264"&gt;
&lt;P&gt;abc with 1 retreatment&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="274"&gt;
&lt;P&gt;Off-study prior to receiving therapy&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="264"&gt;
&lt;P&gt;a&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="274"&gt;
&lt;P&gt;On study, active&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="264"&gt;
&lt;P&gt;b&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="274"&gt;
&lt;P&gt;On study, LTFU&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="264"&gt;
&lt;P&gt;aaa&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="274"&gt;
&lt;P&gt;Deaths while on study and cause of death&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="264"&gt;
&lt;P&gt;xx due to Progressive Disease&lt;/P&gt;
&lt;P&gt;cy due to Transplant Complications&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="274"&gt;
&lt;P&gt;Off-study and reason&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="264"&gt;
&lt;P&gt;ab due to death&lt;/P&gt;
&lt;P&gt;6 due to did not receive CAR T cells&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Fri, 18 Jan 2019 23:40:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-to-concatenate-distinct-number-and-associated-text/m-p/528479#M144241</guid>
      <dc:creator>saslove</dc:creator>
      <dc:date>2019-01-18T23:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-to-concatenate-distinct-number-and-associated-text/m-p/528483#M144245</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;catx( ' - ' ,
       put(count(case when off_study=1 then 1 else . end),2.),
       reason _text)
 as count&lt;/PRE&gt;
&lt;P&gt;Change your last variable to be something like above, basically use CATX to append the data? Where does the 'reason' come from? I'm assuming it's in your data set somewhere.&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/1717"&gt;@saslove&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I need to combine reasons from my dataset to look like these for the ones in the table that have a reason/cause. I have completed the programming part to create the table, but I don't know how to append the reason/cause to the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table table as&lt;BR /&gt; &lt;BR /&gt;select distinct &lt;BR /&gt;1 as no,&lt;BR /&gt;'Enrolled' as descrip,&lt;BR /&gt;put(count(case when enrolled=1 then 1 else . end),2.) as count&lt;BR /&gt;from enrolled&lt;/P&gt;
&lt;P&gt;union&lt;BR /&gt;select distinct &lt;BR /&gt;2 as no,&lt;BR /&gt;'Treated' as descrip,&lt;BR /&gt;put(count(case when treated=1 then 1 else . end),2.) as count&lt;BR /&gt;from treated&lt;/P&gt;
&lt;P&gt;union&lt;BR /&gt;select distinct &lt;BR /&gt;3 as no,&lt;BR /&gt;'Off-study prior to receiving therapy' as descrip,&lt;BR /&gt;put(count(case when offstudy_pre_trt=1 then 1 else . end),2.) as count&lt;BR /&gt;from offstudy_pre_trt&lt;/P&gt;
&lt;P&gt;union&lt;BR /&gt;select distinct &lt;BR /&gt;4 as no,&lt;BR /&gt;'On-study, Active' as descrip,&lt;BR /&gt;put(count(case when off_study=0 then 1 else . end),2.) as count&lt;BR /&gt;from on_study&lt;BR /&gt; &lt;BR /&gt;union&lt;BR /&gt;select distinct &lt;BR /&gt;5 as no,&lt;BR /&gt;'On-study, LTFU' as descrip,&lt;BR /&gt;put(count(case when ltfu=1 then 1 else . end),2.) as count&lt;BR /&gt;from ltfu&lt;/P&gt;
&lt;P&gt;union&lt;BR /&gt;select distinct&lt;BR /&gt;6 as no,&lt;BR /&gt;'Deaths on study and cause of death' as descrip,&lt;BR /&gt;put(count(case when death_onstudy=1 then 1 else . end),2.) as count&lt;BR /&gt;from on_study&lt;/P&gt;
&lt;P&gt;union&lt;BR /&gt;select distinct&lt;BR /&gt;7 as no,&lt;BR /&gt;'Off-study and reason' as descrip,&lt;BR /&gt;put(count(case when off_study=1 then 1 else . end),2.) as count&lt;BR /&gt;from on_study&lt;/P&gt;
&lt;P&gt;order by no;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For #6 and #7, please tell me how to append the associated reason.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is how the table should look:&lt;/P&gt;
&lt;TABLE width="538"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="274"&gt;
&lt;P&gt;Category&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="264"&gt;
&lt;P&gt;Number of Subjects&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="274"&gt;
&lt;P&gt;Enrolled&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="264"&gt;
&lt;P&gt;abc&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="274"&gt;
&lt;P&gt;Treated&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="264"&gt;
&lt;P&gt;abc with 1 retreatment&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="274"&gt;
&lt;P&gt;Off-study prior to receiving therapy&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="264"&gt;
&lt;P&gt;a&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="274"&gt;
&lt;P&gt;On study, active&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="264"&gt;
&lt;P&gt;b&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="274"&gt;
&lt;P&gt;On study, LTFU&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="264"&gt;
&lt;P&gt;aaa&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="274"&gt;
&lt;P&gt;Deaths while on study and cause of death&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="264"&gt;
&lt;P&gt;xx due to Progressive Disease&lt;/P&gt;
&lt;P&gt;cy due to Transplant Complications&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="274"&gt;
&lt;P&gt;Off-study and reason&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="264"&gt;
&lt;P&gt;ab due to death&lt;/P&gt;
&lt;P&gt;6 due to did not receive CAR T cells&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jan 2019 23:41:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-to-concatenate-distinct-number-and-associated-text/m-p/528483#M144245</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-18T23:41:59Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL to concatenate distinct number and associated text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-to-concatenate-distinct-number-and-associated-text/m-p/528485#M144246</link>
      <description>&lt;P&gt;It kinda worked but that row is repeated for every single reason. I want count due to reason , count due to reason, count due to reason. (separated by comma).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please see attached..&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Jan 2019 23:47:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-to-concatenate-distinct-number-and-associated-text/m-p/528485#M144246</guid>
      <dc:creator>saslove</dc:creator>
      <dc:date>2019-01-18T23:47:20Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL to concatenate distinct number and associated text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-to-concatenate-distinct-number-and-associated-text/m-p/528488#M144248</link>
      <description>No attachment was included. CATX() is the function you need to concatenate text comments, so you'll likely want to nest it a bit. I suspect a data step would be a lot easier for this.</description>
      <pubDate>Fri, 18 Jan 2019 23:57:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-to-concatenate-distinct-number-and-associated-text/m-p/528488#M144248</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-18T23:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL to concatenate distinct number and associated text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-to-concatenate-distinct-number-and-associated-text/m-p/528490#M144249</link>
      <description>&lt;P&gt;I am attaching once again..&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In a datastep, how can I get the n&amp;nbsp;and also concatenate separated by a comma on the same row.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 518px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/26372iAABF0F87ECFFDF20/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Jan 2019 00:02:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-to-concatenate-distinct-number-and-associated-text/m-p/528490#M144249</guid>
      <dc:creator>saslove</dc:creator>
      <dc:date>2019-01-19T00:02:27Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL to concatenate distinct number and associated text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-to-concatenate-distinct-number-and-associated-text/m-p/528500#M144252</link>
      <description>AFAIK you cannot easily do that in SQL. You’ll have to change to a data step.</description>
      <pubDate>Sat, 19 Jan 2019 05:35:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-to-concatenate-distinct-number-and-associated-text/m-p/528500#M144252</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-19T05:35:35Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL to concatenate distinct number and associated text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-to-concatenate-distinct-number-and-associated-text/m-p/529061#M144491</link>
      <description>Ok just an update on what I did.&lt;BR /&gt;I used proc freq and did a 2x2 to output the flags and reasons . I used data step to concatenate.</description>
      <pubDate>Tue, 22 Jan 2019 14:50:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-to-concatenate-distinct-number-and-associated-text/m-p/529061#M144491</guid>
      <dc:creator>saslove</dc:creator>
      <dc:date>2019-01-22T14:50:11Z</dc:date>
    </item>
  </channel>
</rss>

