<?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 make flexible code for unstable data set involving counts? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-flexible-code-for-unstable-data-set-involving-counts/m-p/771439#M244816</link>
    <description>Thanks for the reply, I have tried the missing option but i solved my issue by using PROC SUMMARY.</description>
    <pubDate>Thu, 30 Sep 2021 17:55:41 GMT</pubDate>
    <dc:creator>Hello_there</dc:creator>
    <dc:date>2021-09-30T17:55:41Z</dc:date>
    <item>
      <title>How to make flexible code for unstable data set involving counts?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-flexible-code-for-unstable-data-set-involving-counts/m-p/771268#M244708</link>
      <description>&lt;P&gt;For example, let's say a study is still going and you're trying to count subjects who were in a control group, and you're making a table for reasons why they discontinued. Everyone is still in the study, so the data set can be updated later on. Let's say the variables were:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;trt="control"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;terminatedn= 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Terminatedn is the numerical number represented by the reason why they were out of the study, and it ranges from 1-5. Doing a proc freq with an out statement won't work bc there are no observations bc everyone is still in the study.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=data;&lt;BR /&gt;table&amp;nbsp;terminatedn*trt/&amp;nbsp;out=cnt;&lt;BR /&gt;where&amp;nbsp;trt="Control"&amp;nbsp;and&amp;nbsp;terminatedn=2;&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What would be another way to code this so that it can be updated in the future when counts change from 0?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The only way i can think of doing this is by brute force and using a proc sql multiple times like this:&lt;/P&gt;&lt;PRE&gt;proc sql;
 select count(distinct subjects) into: cnt_contrl2
 from data
 where trt="Control" and terminatedn=2;
quit;&lt;/PRE&gt;&lt;P&gt;This would produce a macro variable that's equal to 0, which i could put into a datalines data step. And then i can if the count is not equal to zero, then do:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But maybe there's an easier way?&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;&lt;P&gt;Thanks for taking it easy to me. I'm a new programmer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 01:27:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-flexible-code-for-unstable-data-set-involving-counts/m-p/771268#M244708</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2021-09-30T01:27:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to make flexible code for unstable data set involving counts?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-flexible-code-for-unstable-data-set-involving-counts/m-p/771269#M244709</link>
      <description>&lt;P&gt;Here's a step you could play with:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   if done then do;
      file print;
      put 'No subjects have terminated.';
   end;
   stop;
   set have end=done;
   where trt="Control" and terminatedn=2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Keep the PROC FREQ in the program.&amp;nbsp; Now what happens is only one step generates output.&amp;nbsp; If there are no terminated subjects, this step writes a message and PROC FREQ generates nothing.&amp;nbsp; If there are terminated subjects, PROC FREQ generates a table, while this new step generates nothing.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 01:39:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-flexible-code-for-unstable-data-set-involving-counts/m-p/771269#M244709</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-09-30T01:39:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to make flexible code for unstable data set involving counts?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-flexible-code-for-unstable-data-set-involving-counts/m-p/771277#M244712</link>
      <description>&lt;P&gt;Have you ever tried the MISSING option on a table:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;proc freq data=data;table terminatedn*trt/missing out=cnt;where trt="Control";run;&lt;/LI-CODE&gt;
&lt;P&gt;Which will show terminatedn is missing but will count the values regardless.&lt;/P&gt;
&lt;P&gt;Filter the OUT= data set for terminatedn=2 for other uses when you &lt;STRONG&gt;need&lt;/STRONG&gt;&amp;nbsp; and expect that value to be present.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 02:21:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-flexible-code-for-unstable-data-set-involving-counts/m-p/771277#M244712</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-09-30T02:21:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to make flexible code for unstable data set involving counts?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-make-flexible-code-for-unstable-data-set-involving-counts/m-p/771439#M244816</link>
      <description>Thanks for the reply, I have tried the missing option but i solved my issue by using PROC SUMMARY.</description>
      <pubDate>Thu, 30 Sep 2021 17:55:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-make-flexible-code-for-unstable-data-set-involving-counts/m-p/771439#M244816</guid>
      <dc:creator>Hello_there</dc:creator>
      <dc:date>2021-09-30T17:55:41Z</dc:date>
    </item>
  </channel>
</rss>

