<?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: Advanced Analysis on Data Set in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/375027#M276231</link>
    <description>&lt;PRE&gt;982   DATA WORK;
983   set data_full;
984   prior_data = lag(_variable);
985   if _n_=1 and variable &amp;lt; 50 then variable_group=1;
986   if(variable &amp;gt;= 50 and prior_data &amp;lt; 50) or (variable &amp;lt; 50 and prior_data &amp;gt;= 50) then do;
987   variable_group + 1;
988   n_seconds_data = 1;
989   end;
990   else n_seconds_data + 1;
991   drop prior_data;
992   run;

NOTE: There were 1200 observations read from the data set WORK.DATA_FULL.
NOTE: The data set WORK.WORK has 1200 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.01 seconds


993
994   proc freq data=WORK.data_full;
995   where variable_group &amp;gt; 1 and variable &amp;gt;= 50;
ERROR: Variable variable_group is not on file WORK.DATA_FULL.
996   tables n_seconds_data;
ERROR: Variable N_SECONDS_DATA not found.
997   run;&lt;/PRE&gt;&lt;P&gt;Yes, when importing from Excel I have noticed changes in variable names; however, the issue looks like it is related to the variables being created in the first step you posted. &amp;nbsp;They are not being recognized. &amp;nbsp;Do I need to add these variables to the dataset separately?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Jul 2017 15:56:30 GMT</pubDate>
    <dc:creator>BC33</dc:creator>
    <dc:date>2017-07-11T15:56:30Z</dc:date>
    <item>
      <title>Advanced Analysis on Data Set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/373743#M276227</link>
      <description>&lt;P&gt;I have a dataset where the first column is a datetime, and the other columns contain integers. &amp;nbsp;Each row represents one second with corresponding values.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How would I find out how many times a value in the integer column was under 50 and then went over 50 for a minimum of n seconds?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I realize this may be a complex solution, so please let me know if you need more info!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 18:46:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/373743#M276227</guid>
      <dc:creator>BC33</dc:creator>
      <dc:date>2017-07-06T18:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: Advanced Analysis on Data Set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/373779#M276228</link>
      <description>&lt;P&gt;I would add variables to your data set, to give you flexibility in the later analysis.&amp;nbsp; It's a bit of a headache, but here is the idea.&amp;nbsp; Let's assume one of your existing variables is named ABC:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;prior_abc = lag(abc);&lt;/P&gt;
&lt;P&gt;if _n_=1 and abc &amp;lt; 50 then abc_group=1;&lt;/P&gt;
&lt;P&gt;if (abc &amp;gt;= 50 and prior_abc &amp;lt; 50) or (abc &amp;lt; 50 and prior_abc &amp;gt;= 50) then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; abc_group + 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; n_seconds_abc = 1;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;else n_seconds_abc + 1;&lt;/P&gt;
&lt;P&gt;drop prior_abc;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that I included 50 exactly as part of the 50+ group.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should be able to run this on your data and get an idea of what the new variables look like.&amp;nbsp; I tested at least some variations of the code.&amp;nbsp; Note that the number of seconds in the first grouping may be off, but that won't matter since the first grouping is never used for analysis.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then consider an analysis question:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For ABC, how many times was the value under 50, then rose to 50+?&amp;nbsp; How long did the 50+ measurement last at least N seconds?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc freq data=want;&lt;/P&gt;
&lt;P&gt;where abc_group &amp;gt; 1 and abc &amp;gt;= 50;&lt;/P&gt;
&lt;P&gt;tables n_seconds_abc;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Test it with a relatively small amount of data to get a feel for what the new variables and the tabular results represent.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jul 2017 20:48:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/373779#M276228</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-06T20:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: Advanced Analysis on Data Set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/373952#M276229</link>
      <description>&lt;P&gt;I appreciate your response. &amp;nbsp;This is definitely getting me on the right track! &amp;nbsp;However, I am getting an error. &amp;nbsp;It is saying the new variables are "&lt;STRONG&gt;not on file&lt;/STRONG&gt;" for the dataset. &amp;nbsp;I did use&amp;nbsp;your code and switched abc for the real variable name. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I imported the data from excel and it lives in a table. &amp;nbsp;Does this change anything?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jul 2017 13:08:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/373952#M276229</guid>
      <dc:creator>BC33</dc:creator>
      <dc:date>2017-07-07T13:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: Advanced Analysis on Data Set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/374609#M276230</link>
      <description>&lt;P&gt;Post the actual log with error messages here using the code box opened with the forum {i} menu icon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Importing from Excel may have a number of issues such as you thinking you know the name of the variable(column heading) but the imported result having additional characters such as _ from spaces or other invalid characters in the variable name&amp;nbsp;or requiring use of "name with space"n syntax.&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jul 2017 17:40:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/374609#M276230</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-07-10T17:40:45Z</dc:date>
    </item>
    <item>
      <title>Re: Advanced Analysis on Data Set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/375027#M276231</link>
      <description>&lt;PRE&gt;982   DATA WORK;
983   set data_full;
984   prior_data = lag(_variable);
985   if _n_=1 and variable &amp;lt; 50 then variable_group=1;
986   if(variable &amp;gt;= 50 and prior_data &amp;lt; 50) or (variable &amp;lt; 50 and prior_data &amp;gt;= 50) then do;
987   variable_group + 1;
988   n_seconds_data = 1;
989   end;
990   else n_seconds_data + 1;
991   drop prior_data;
992   run;

NOTE: There were 1200 observations read from the data set WORK.DATA_FULL.
NOTE: The data set WORK.WORK has 1200 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.01 seconds


993
994   proc freq data=WORK.data_full;
995   where variable_group &amp;gt; 1 and variable &amp;gt;= 50;
ERROR: Variable variable_group is not on file WORK.DATA_FULL.
996   tables n_seconds_data;
ERROR: Variable N_SECONDS_DATA not found.
997   run;&lt;/PRE&gt;&lt;P&gt;Yes, when importing from Excel I have noticed changes in variable names; however, the issue looks like it is related to the variables being created in the first step you posted. &amp;nbsp;They are not being recognized. &amp;nbsp;Do I need to add these variables to the dataset separately?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jul 2017 15:56:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/375027#M276231</guid>
      <dc:creator>BC33</dc:creator>
      <dc:date>2017-07-11T15:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: Advanced Analysis on Data Set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/375083#M276232</link>
      <description>&lt;P&gt;You've called the new data set "work" (probably not a good name)&lt;/P&gt;
&lt;PRE&gt;982   DATA WORK;&lt;/PRE&gt;
&lt;P&gt;so you need to use that name in PROC FREQ:&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;994   proc freq data=WORK;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Jul 2017 18:44:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/375083#M276232</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-07-11T18:44:45Z</dc:date>
    </item>
    <item>
      <title>Re: Advanced Analysis on Data Set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/375174#M276233</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data HAVE;
  do DT=1 to 1000;
    VAL=ranuni(0)*200;
    output;
  end;
run;

%let nb_seconds=10;

data COUNT;
  set HAVE end=LASTOBS;
  if VAL &amp;gt; 50 then SEQ+1;
  else SEQ=0;
  if SEQ = &amp;amp;nb_seconds. then GROUP+1;
  if LASTOBS then putlog GROUP=;
run;

  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;GROUP=10&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 01:43:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/375174#M276233</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-07-12T01:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: Advanced Analysis on Data Set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/375291#M276234</link>
      <description>&lt;P&gt;You are correct. &amp;nbsp;I am now getting the expected results. &amp;nbsp;Thanks for the tip!&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 12:53:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/375291#M276234</guid>
      <dc:creator>BC33</dc:creator>
      <dc:date>2017-07-12T12:53:29Z</dc:date>
    </item>
    <item>
      <title>Re: Advanced Analysis on Data Set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/375469#M276235</link>
      <description>&lt;P&gt;Thanks for your answer. &amp;nbsp;I realize this next solution may be similar in manner, but &lt;STRONG&gt;how would you best find how many events there are&amp;nbsp;where x &amp;gt; 50 for 10 consecutive seconds (or rows)&lt;/STRONG&gt;? &amp;nbsp;As you may have guessed, I am a beginner at SAS programming. &amp;nbsp;Your help is greatly appreciated!&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;</description>
      <pubDate>Wed, 12 Jul 2017 19:28:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/375469#M276235</guid>
      <dc:creator>BC33</dc:creator>
      <dc:date>2017-07-12T19:28:07Z</dc:date>
    </item>
    <item>
      <title>Re: Advanced Analysis on Data Set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/375527#M276236</link>
      <description>&lt;P&gt;?? &amp;nbsp;That's what my code does.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 22:29:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/375527#M276236</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-07-12T22:29:06Z</dc:date>
    </item>
    <item>
      <title>Re: Advanced Analysis on Data Set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/376010#M276237</link>
      <description>&lt;P&gt;Can you please explain what this does? &amp;nbsp;I run your code and get a GROUP= output, but the output value doesn't quite seem to match what I am looking for, and I suspect it could be this code. &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;VAL=ranuni(0)*200;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 14:16:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/376010#M276237</guid>
      <dc:creator>BC33</dc:creator>
      <dc:date>2017-07-14T14:16:13Z</dc:date>
    </item>
    <item>
      <title>Re: Advanced Analysis on Data Set</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/376051#M276238</link>
      <description>&lt;P&gt;No worries. &amp;nbsp;I have refined the code to use values from the dataset instead of random numbers and your code works great. &amp;nbsp;Although the original question had a slightly different context, I still appreciate your solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 14 Jul 2017 15:10:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Advanced-Analysis-on-Data-Set/m-p/376051#M276238</guid>
      <dc:creator>BC33</dc:creator>
      <dc:date>2017-07-14T15:10:41Z</dc:date>
    </item>
  </channel>
</rss>

