<?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 using calculated variable in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-freq-using-calculated-variable/m-p/490772#M31648</link>
    <description>&lt;P&gt;Nope, you would need to datepart the date into a new variable first.&lt;/P&gt;
&lt;P&gt;You do of course realise there are various mistakes in both sets of code there?&amp;nbsp; An arrow in the select before format for instance, or missing end bracket in the where of the second code, not to mention a macro variable not used in the first code.&amp;nbsp; Also, please use a code window - its the {i} above the post area for code in future, its very hard to read the code presented there.&lt;/P&gt;
&lt;PRE&gt;data want;
  set dataflow.datasource;
  dvar=datepart(datecreated);
  format dvar date9.;
run;

proc freq data=dataflow.datasource;
  tables dvar;
  where dvar ge intnx('month',&amp;amp;month.,0,'b');
run;&lt;/PRE&gt;</description>
    <pubDate>Wed, 29 Aug 2018 10:48:54 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-08-29T10:48:54Z</dc:date>
    <item>
      <title>Proc freq using calculated variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-freq-using-calculated-variable/m-p/490766#M31646</link>
      <description>&lt;P&gt;Hi There,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am looking to create a PROC FREQ output to do a quick check on the number of variables for each day past a certain&amp;nbsp;date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This issue is the date field in the source table is in date time format (e.g.&amp;nbsp;07AUG2006:16:25:00).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I currently do this in PROC SQL with the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Proc SQL;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Create table&amp;nbsp;DateCheck as&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Select &lt;/STRONG&gt;datepart&lt;STRONG&gt;(DateCreated)&amp;gt; format date9. as date, Count(*) as Volume&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;From&amp;nbsp;dataflow.datasource&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Where &lt;/STRONG&gt;datepart&lt;STRONG&gt;(DateCreated)&amp;gt;='01JUL2018'd&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;group by date;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;Quit;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, I would like to be able to do a PROC FREQ like this but it will not allow the datepart&amp;nbsp;function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc freq data=dataflow.datasource;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;tables &lt;/STRONG&gt;datepart&lt;STRONG&gt;(DateCreated);&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;where &lt;/STRONG&gt;datepart&lt;STRONG&gt;(DateCreated GE &lt;/STRONG&gt;intnx&lt;STRONG&gt;('month',&amp;amp;month.,0,&lt;/STRONG&gt;'b&lt;STRONG&gt;');&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;format DateCreated&amp;nbsp;date9.;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this possible?&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;Jon&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 10:19:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-freq-using-calculated-variable/m-p/490766#M31646</guid>
      <dc:creator>rowansdad</dc:creator>
      <dc:date>2018-08-29T10:19:00Z</dc:date>
    </item>
    <item>
      <title>Re: Proc freq using calculated variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-freq-using-calculated-variable/m-p/490769#M31647</link>
      <description>&lt;P&gt;You can move the where statement into a where= dataset option, but the use of a data step function in proc freq itself does not work. In a tables statement, only existing variables can be used.&lt;/P&gt;
&lt;P&gt;One of the reasons that proc freq outperforms SQL is this restriction.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Aug 2018 10:42:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-freq-using-calculated-variable/m-p/490769#M31647</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-29T10:42:38Z</dc:date>
    </item>
    <item>
      <title>Re: Proc freq using calculated variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-freq-using-calculated-variable/m-p/490772#M31648</link>
      <description>&lt;P&gt;Nope, you would need to datepart the date into a new variable first.&lt;/P&gt;
&lt;P&gt;You do of course realise there are various mistakes in both sets of code there?&amp;nbsp; An arrow in the select before format for instance, or missing end bracket in the where of the second code, not to mention a macro variable not used in the first code.&amp;nbsp; Also, please use a code window - its the {i} above the post area for code in future, its very hard to read the code presented there.&lt;/P&gt;
&lt;PRE&gt;data want;
  set dataflow.datasource;
  dvar=datepart(datecreated);
  format dvar date9.;
run;

proc freq data=dataflow.datasource;
  tables dvar;
  where dvar ge intnx('month',&amp;amp;month.,0,'b');
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Aug 2018 10:48:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-freq-using-calculated-variable/m-p/490772#M31648</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-08-29T10:48:54Z</dc:date>
    </item>
    <item>
      <title>Re: Proc freq using calculated variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-freq-using-calculated-variable/m-p/490895#M31650</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/57100"&gt;@rowansdad&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you need the &lt;A href="https://documentation.sas.com/?docsetId=leforinforref&amp;amp;docsetTarget=n1wi7cnt9ozjwan1gl0397h6b0n1.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;DTDATE&lt;EM&gt;w.&lt;/EM&gt; format&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input DateCreated datetime.;
cards;
30JUN2006:16:25:00
07AUG2006:16:25:00
07AUG2006:16:26:00
08AUG2006:16:25:00
;

proc freq data=have;
format DateCreated dtdate9.;
tables DateCreated;
where datepart(DateCreated) ge '01JUL2006'd;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Aug 2018 15:48:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-freq-using-calculated-variable/m-p/490895#M31650</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-08-29T15:48:27Z</dc:date>
    </item>
    <item>
      <title>Re: Proc freq using calculated variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-freq-using-calculated-variable/m-p/490898#M31652</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/57100"&gt;@rowansdad&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi There,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am looking to create a PROC FREQ output to do a quick check on the number of variables for each day past a certain&amp;nbsp;date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not quite clear on what this means. The number of variables in a data doesn't change based on the value of a variable. Do you mean the number of variables with non-missing values?? The code looks more like you a looking for the number of records where a variable is within a stated range of values.&lt;/P&gt;
&lt;P&gt;And there really isn't much reason to play around with extracting dateparts as a format applied to an existing value will count days based on datetime values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data example;
  informat dt datetime18.;
  input dt;
  format dt datetime18.;
datalines;
01MAR2018:01:02:03
01MAR2018:01:03:03
01MAR2018:01:04:03
01MAR2018:01:05:03
01MAR2018:01:06:03
03MAR2018:01:03:03
03MAR2018:01:04:03
03MAR2018:01:05:03
04MAR2018:01:06:03
;
run;

proc freq data=example;
   format dt datetime9.;
   tables dt;
run; &lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Aug 2018 15:52:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-freq-using-calculated-variable/m-p/490898#M31652</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-29T15:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: Proc freq using calculated variable</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-freq-using-calculated-variable/m-p/491135#M31666</link>
      <description>Thanks, that's worked great.</description>
      <pubDate>Thu, 30 Aug 2018 08:44:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Proc-freq-using-calculated-variable/m-p/491135#M31666</guid>
      <dc:creator>rowansdad</dc:creator>
      <dc:date>2018-08-30T08:44:34Z</dc:date>
    </item>
  </channel>
</rss>

