<?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 freq with a division in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-with-a-division/m-p/859917#M339709</link>
    <description>&lt;P&gt;This seemed to work! Thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 21 Feb 2023 13:56:22 GMT</pubDate>
    <dc:creator>KarinGun</dc:creator>
    <dc:date>2023-02-21T13:56:22Z</dc:date>
    <item>
      <title>proc freq with a division</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-with-a-division/m-p/859721#M339639</link>
      <description>&lt;P&gt;Dear all!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following problem:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to do a proc freq with two variables (var1*var2) but then I would like to divide the frequency counts by a third variable (var3).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Something like:&lt;/P&gt;&lt;P&gt;proc freq data = sas;&lt;/P&gt;&lt;P&gt;tables (var1*var2)/var3;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Var1 and var3 are numerical/continuous, var2 is cathegorical.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The example above is not acceptable SAS syntax and I wonder if anyone have any suggestions on how to solve this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you on beforehand!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best regards,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Karin Gunnarsson&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2023 14:58:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-with-a-division/m-p/859721#M339639</guid>
      <dc:creator>KarinGun</dc:creator>
      <dc:date>2023-02-20T14:58:10Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq with a division</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-with-a-division/m-p/859725#M339642</link>
      <description>&lt;P&gt;Strange question , but you could probably make creative use of the WEIGHT statement, no?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data = sashelp.class;
tables age*sex / missing list;
run;

proc freq data = sashelp.class;
tables age*sex / missing list;
weight height;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2023 15:28:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-with-a-division/m-p/859725#M339642</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2023-02-20T15:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq with a division</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-with-a-division/m-p/859728#M339643</link>
      <description>&lt;P&gt;Thanks for your quick reply!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I couldn't really make it work out by your solution though.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The reason I want to divide is to get a frequency proportion as the individuals in my datset have different&amp;nbsp; follow up and I want to calculate proportions related to the number of individuals still at risk.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Var1 is a time cathegory variable, var2 is having a disease of no. Var3 is numbers still at risk related to that time interval. The goal is to make a side to side histogram presenting proportions in two groups.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2023 15:45:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-with-a-division/m-p/859728#M339643</guid>
      <dc:creator>KarinGun</dc:creator>
      <dc:date>2023-02-20T15:45:10Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq with a division</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-with-a-division/m-p/859734#M339645</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can't you provide us with some data (data step with datalines).&lt;/P&gt;
&lt;P&gt;A HAVE dataset and possibly a WANT dataset as well?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's some code for your comparative histograms :&lt;/P&gt;
&lt;P&gt;Comparative histograms: Panel and overlay histograms in SAS &lt;BR /&gt;By Rick Wicklin on The DO Loop March 9, 2016&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/iml/2016/03/09/comparative-panel-overlay-histograms-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2016/03/09/comparative-panel-overlay-histograms-sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2023 16:05:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-with-a-division/m-p/859734#M339645</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2023-02-20T16:05:36Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq with a division</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-with-a-division/m-p/859735#M339646</link>
      <description>&lt;P&gt;In the suggestion above by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/60547"&gt;@sbxkoenk&lt;/a&gt; , if you make var3a have the value&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;var3a=1/var3;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then the WEIGHT statement in PROC FREQ ought to give you the division by var3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data = yourdatasetname;
    tables var1*var2/ missing list;
    weight var3a;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Feb 2023 16:23:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-with-a-division/m-p/859735#M339646</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-02-20T16:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq with a division</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-with-a-division/m-p/859852#M339684</link>
      <description>&lt;P&gt;Hello again,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example of datalines:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data test_data;&lt;BR /&gt;input runnumber timediff ssc $ sar;&lt;BR /&gt;datalines;&lt;BR /&gt;1 3 patient 9&lt;BR /&gt;2 4 comparator 8&lt;BR /&gt;3 2 comparator 6&lt;BR /&gt;4 4 patient 5&lt;BR /&gt;5 5 patient 5&lt;BR /&gt;6 7 comparator 4&lt;BR /&gt;7 8 patient 3&lt;BR /&gt;8 2 comparator 3&lt;BR /&gt;9 4 comparator 3&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is how I have coded the timediff variable in my program, it calculates how many patients got cancer in these timeintervals from an index date (called date_2).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data exit4;&lt;BR /&gt;set exit3;&lt;BR /&gt;if cancerdat ne "." then do timedif =((cancerdat-date_2)/365.25);/*defining the new varible timedif in years*/&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And then I have calculated time cathegories for the timedif variable (now called timediff):&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data exit5;&lt;BR /&gt;set exit4;&lt;BR /&gt;if timedif = 0 then timediff = "index";&lt;BR /&gt;if timedif GT 0 and timedif LE 2 then timediff = "0-2";&lt;BR /&gt;if timedif GT 2 and timedif LE 4 then timediff = "2-4";&lt;BR /&gt;if timedif GT 4 and timedif LE 6 then timediff = "4-6";&lt;BR /&gt;if timedif GT 6 and timedif LE 8 then timediff = "6-8";&lt;BR /&gt;if timedif GT 8 and timedif LE 10 then timediff = "8-10";&lt;BR /&gt;if timedif GT 10 then timediff = "&amp;gt;10";&lt;BR /&gt;if timedif LT 0 and timedif GE -2 then timediff = "-2-0";&lt;BR /&gt;if timedif LT -2 and timedif GE -4 then timediff = "-2-4";&lt;BR /&gt;if timedif LT -4 and timedif GE -6 then timediff = "-4-6";&lt;BR /&gt;if timedif LT -6 and timedif GE -8 then timediff = "-6-8";&lt;BR /&gt;if timedif LT -8 and timedif GE -10 then timediff = "-8-10";&lt;BR /&gt;if timedif LT -10 and timedif GE -12 then timediff = "-10-12";&lt;BR /&gt;if timedif LT -12 and timedif GE -14 then timediff = "-12-14";&lt;BR /&gt;if timedif LT -14 and timedif GE -20 then timediff = "-14-20";&lt;BR /&gt;if timedif LT -20 then timediff = "&amp;gt;-20";&lt;BR /&gt;if cancerdat NE "." then output;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2023 07:27:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-with-a-division/m-p/859852#M339684</guid>
      <dc:creator>KarinGun</dc:creator>
      <dc:date>2023-02-21T07:27:15Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq with a division</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-with-a-division/m-p/859883#M339700</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/404370"&gt;@KarinGun&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And then I have calculated time cathegories for the timedif variable (now called timediff):&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data exit5;&lt;BR /&gt;set exit4;&lt;BR /&gt;if timedif = 0 then timediff = "index";&lt;BR /&gt;if timedif GT 0 and timedif LE 2 then timediff = "0-2";&lt;BR /&gt;if timedif GT 2 and timedif LE 4 then timediff = "2-4";&lt;BR /&gt;if timedif GT 4 and timedif LE 6 then timediff = "4-6";&lt;BR /&gt;if timedif GT 6 and timedif LE 8 then timediff = "6-8";&lt;BR /&gt;if timedif GT 8 and timedif LE 10 then timediff = "8-10";&lt;BR /&gt;if timedif GT 10 then timediff = "&amp;gt;10";&lt;BR /&gt;if timedif LT 0 and timedif GE -2 then timediff = "-2-0";&lt;BR /&gt;if timedif LT -2 and timedif GE -4 then timediff = "-2-4";&lt;BR /&gt;if timedif LT -4 and timedif GE -6 then timediff = "-4-6";&lt;BR /&gt;if timedif LT -6 and timedif GE -8 then timediff = "-6-8";&lt;BR /&gt;if timedif LT -8 and timedif GE -10 then timediff = "-8-10";&lt;BR /&gt;if timedif LT -10 and timedif GE -12 then timediff = "-10-12";&lt;BR /&gt;if timedif LT -12 and timedif GE -14 then timediff = "-12-14";&lt;BR /&gt;if timedif LT -14 and timedif GE -20 then timediff = "-14-20";&lt;BR /&gt;if timedif LT -20 then timediff = "&amp;gt;-20";&lt;BR /&gt;if cancerdat NE "." then output;&lt;BR /&gt;run;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This will never work. You should be getting errors in the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of IF-THEN to create categories, use a custom format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
     value timef 
         0='index' 
         0&amp;lt;-2='0-2'
         2&amp;lt;-4='2-4'
         /* I'm lazy you type the rest */
run;
proc freq data=have;
     format timedif timef.;
     /* The rest of your PROC FREQ goes here */
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Feb 2023 10:56:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-with-a-division/m-p/859883#M339700</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-02-21T10:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq with a division</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-with-a-division/m-p/859916#M339708</link>
      <description>Actually no errors in the log but thanks for a suggestion of a smoother solution &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Tue, 21 Feb 2023 13:55:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-with-a-division/m-p/859916#M339708</guid>
      <dc:creator>KarinGun</dc:creator>
      <dc:date>2023-02-21T13:55:58Z</dc:date>
    </item>
    <item>
      <title>Re: proc freq with a division</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-freq-with-a-division/m-p/859917#M339709</link>
      <description>&lt;P&gt;This seemed to work! Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2023 13:56:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-freq-with-a-division/m-p/859917#M339709</guid>
      <dc:creator>KarinGun</dc:creator>
      <dc:date>2023-02-21T13:56:22Z</dc:date>
    </item>
  </channel>
</rss>

