<?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: Summarizing data in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Summarizing-data/m-p/803934#M33369</link>
    <description>&lt;P&gt;next time, please post your data as datalines.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID treatment;
datalines;
1 0
1 1
1 1
2 1
2 3
2 3
3 0
3 0
3 0
;
proc print;
run;

data have2;
	set have;
	trt=treatment &amp;gt; 0;
run;

proc sort data=have2;
	by id descending treatment;
run;

data want;
	set have2;
	by id descending treatment;
	if first.id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 25 Mar 2022 00:00:45 GMT</pubDate>
    <dc:creator>tarheel13</dc:creator>
    <dc:date>2022-03-25T00:00:45Z</dc:date>
    <item>
      <title>Summarizing data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Summarizing-data/m-p/803931#M33367</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a dataset, I want to select the IDs who have had treatment (0) vs those who have not(&amp;gt;0) and create. The summary should have only one ID per subject.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The below is my data.&lt;/P&gt;&lt;P&gt;ID treatment&lt;/P&gt;&lt;P&gt;1 0&lt;/P&gt;&lt;P&gt;1 1&lt;/P&gt;&lt;P&gt;1 1&lt;/P&gt;&lt;P&gt;2 1&lt;/P&gt;&lt;P&gt;2 3&lt;/P&gt;&lt;P&gt;2 3&lt;/P&gt;&lt;P&gt;3 0&lt;/P&gt;&lt;P&gt;3 0&lt;/P&gt;&lt;P&gt;3 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How it should look like&lt;/P&gt;&lt;P&gt;ID&amp;nbsp;&amp;nbsp; Treatment(Dichotomous)&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Mar 2022 23:47:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Summarizing-data/m-p/803931#M33367</guid>
      <dc:creator>ppl</dc:creator>
      <dc:date>2022-03-24T23:47:51Z</dc:date>
    </item>
    <item>
      <title>Re: Summarizing data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Summarizing-data/m-p/803934#M33369</link>
      <description>&lt;P&gt;next time, please post your data as datalines.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID treatment;
datalines;
1 0
1 1
1 1
2 1
2 3
2 3
3 0
3 0
3 0
;
proc print;
run;

data have2;
	set have;
	trt=treatment &amp;gt; 0;
run;

proc sort data=have2;
	by id descending treatment;
run;

data want;
	set have2;
	by id descending treatment;
	if first.id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Mar 2022 00:00:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Summarizing-data/m-p/803934#M33369</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2022-03-25T00:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: Summarizing data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Summarizing-data/m-p/803941#M33373</link>
      <description>&lt;P&gt;For each ID, read all the treatment&amp;gt;0 cases followed by all the without-treatment cases.&amp;nbsp; Then just keep the first obs for each id and test its TREATMENT variable against 0.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID treatment;
datalines;
1 0
1 1
1 1
2 1
2 3
2 3
3 0
3 0
3 0
run;
data want (drop=treatment);
  set have (where=(treatment&amp;gt;0)) have (where=(treatment=0));
  by id;
  if first.id;
  trt_dummy=(treatment&amp;gt;0);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This works if the data are already sorted by ID.&amp;nbsp; But it doesn't matter what the order is within each ID.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2022 00:25:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Summarizing-data/m-p/803941#M33373</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-03-25T00:25:12Z</dc:date>
    </item>
    <item>
      <title>Re: Summarizing data</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Summarizing-data/m-p/804037#M33396</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID treatment;
cards;
1 0
1 1
1 1
2 1
2 3
2 3
3 0
3 0
3 0
;

proc sql;
create table want as
select id,sum(treatment&amp;gt;0) ne 0 as flag
 from have 
  group by id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 25 Mar 2022 12:12:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Summarizing-data/m-p/804037#M33396</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-03-25T12:12:58Z</dc:date>
    </item>
  </channel>
</rss>

