<?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: Generate new difficult variable that count observations based on location in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/642358#M191599</link>
    <description>&lt;P&gt;Hi again&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have checked the following and can add:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) When I look in the original datasets (Data_komplet and Final_database), the 'eventtime' (from Final_database) is numeric with the format &lt;EM&gt;datetime19.&lt;/EM&gt; while the 'time' (from Data_komplet) is numeric with the format &lt;EM&gt;datetime18.&amp;nbsp;&lt;/EM&gt;(I rightclick on the variable name and press 'properties' where the type and format e.g. numeric and datetime19. is shown. The same is found when using PROC CONTETNS).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is that ok? Or should 'time' and 'eventtime' have the same format (e.g. datetime19. or datetime18.)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) In both datasets I see human readable values (in Data_komplet e.g. 12MAY0714:40:00 and in Final_database e.g. 01JUN2018:10:46:45 - that is, there is a difference the datasets between with a "missing" colon between the year and time in Data_komplet and a "missing" 20 in year in Data_komplet. I am not sure whether this will hinder analyses.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3) In Final_database the median is 1838539767 while the median in Data_komplet is 1789633440 (though I guess this is because I have observations older than 2017 in the Data_komplet dataset e.g. from 2007).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4) I changed the 'year' to 'dtyear' it did, however, result in a significant drop in observations in d0_500, d500_1000, and d1000_1500 ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know I must sound a bit confused, but I'm very thankful for your enormous help! I might have some extra questions and wishes to the program, but I will focuse on the problems above first. Once again, thank you!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 23 Apr 2020 18:23:50 GMT</pubDate>
    <dc:creator>Mikkel_madsen</dc:creator>
    <dc:date>2020-04-23T18:23:50Z</dc:date>
    <item>
      <title>Generate new difficult variable that count observations based on location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/641198#M191078</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm quite new to SAS and have a complicated question. Hope someone is able to help me out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Imagine this fictive dataset lets call it "Main_dataset":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp;Longitude&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Lattitude&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Day&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;12.21236548&amp;nbsp; &amp;nbsp; &amp;nbsp;55.14578965&amp;nbsp; &amp;nbsp; &amp;nbsp;15FEB2017&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;12.52319752&amp;nbsp; &amp;nbsp; &amp;nbsp;55.21460198&amp;nbsp; &amp;nbsp; &amp;nbsp;19FEB2017&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;12.41219754&amp;nbsp; &amp;nbsp; &amp;nbsp;56.41301547&amp;nbsp; &amp;nbsp; &amp;nbsp;21APR2017&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp;12.14016597&amp;nbsp; &amp;nbsp; &amp;nbsp;55.49783265&amp;nbsp; &amp;nbsp; &amp;nbsp;05JUN2018&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp;12.13497326&amp;nbsp; &amp;nbsp; &amp;nbsp;55.65794325&amp;nbsp; &amp;nbsp; &amp;nbsp;21DEC2018&lt;/P&gt;&lt;P&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp;12.52319632&amp;nbsp; &amp;nbsp; &amp;nbsp;55.21446125&amp;nbsp; &amp;nbsp; &amp;nbsp;26DEC2018&lt;/P&gt;&lt;P&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp;12.41659721&amp;nbsp; &amp;nbsp; &amp;nbsp;56.41302146&amp;nbsp; &amp;nbsp; &amp;nbsp;21APR2019&lt;/P&gt;&lt;P&gt;8&amp;nbsp; &amp;nbsp; &amp;nbsp;12.14316592&amp;nbsp; &amp;nbsp; &amp;nbsp;55.49789875&amp;nbsp; &amp;nbsp; &amp;nbsp;05JUN2019&lt;/P&gt;&lt;P&gt;9&amp;nbsp; &amp;nbsp; &amp;nbsp;12.13478134&amp;nbsp; &amp;nbsp; &amp;nbsp;55.65795469&amp;nbsp; &amp;nbsp; &amp;nbsp;21DEC2019&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I have three other datasets (that are quite similar) lets call them "Observations_2017", "Observations_2018", and "Observations_2019". The only difference, is that the observations in each of them at limited to that year (2017, 2018, 2019).&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lets look at one of them fx "Observations_2017":&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Day&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Longitude&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Lattitude&lt;/P&gt;&lt;P&gt;01FEB2017&amp;nbsp; &amp;nbsp; &amp;nbsp;12.62315456&amp;nbsp; &amp;nbsp; &amp;nbsp;55.46532659&lt;/P&gt;&lt;P&gt;21FEB2017&amp;nbsp; &amp;nbsp; &amp;nbsp;12.65312348&amp;nbsp; &amp;nbsp; &amp;nbsp;55.64325689&lt;/P&gt;&lt;P&gt;05MAR2017&amp;nbsp; &amp;nbsp; 12.54693265&amp;nbsp; &amp;nbsp; &amp;nbsp;55.21302356&lt;/P&gt;&lt;P&gt;12JUN2017&amp;nbsp; &amp;nbsp; &amp;nbsp;12.06837264&amp;nbsp; &amp;nbsp; &amp;nbsp;55.21363221&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So.. What I want is to generate three new variables in my "Main_dataset" called "0_500", "500_1000" and "1000_1500". If we take first observation in the "Main_dataset" with ID = 1, then I want the three new variables to count how many observations from the "Observations_2017" (because the variable "Day" in the "Main_dataset" is 2017) that took place in 0-500, 500-1000, and 1000-1500 meters away from the coordinates in ID = 1. It should only look for events that happened at or before 15FEB2017 (the "Day" in ID = 1). In this fictive dataset, I'm not sure, that the variables actually are within these distances from each other. True line distance would be preferred, but straight line is also acceptable if true line is impossible. If the "Day" in the "Main_dataset" are from 2018 or 2019 the new variables should be generated from "Observations_2018" or "Observations_2019) respectively.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't get my mind around this. Hope someone can help, and that the question is understandable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Apr 2020 07:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/641198#M191078</guid>
      <dc:creator>Mikkel_madsen</dc:creator>
      <dc:date>2020-04-20T07:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Generate new difficult variable that count observations based on location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/641230#M191088</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/324058"&gt;@Mikkel_madsen&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would (temporarily) combine the three "Observations" datasets and then apply PROC SQL, using the &lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n1korpfg2e18lon1nwpow9qijdxe.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;GEODIST function&lt;/A&gt; (which returns the &lt;EM&gt;geodetic&lt;/EM&gt; distance, if that is acceptable).&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;/* Create test data */

data main;
input ID Longitude Latitude Day :date9.;
format day date9.;
cards;
1 12.21236548 55.14578965 15FEB2017
2 12.52319752 55.21460198 19FEB2017
3 12.41219754 56.41301547 21APR2017
4 12.14016597 55.49783265 05JUN2018
5 12.13497326 55.65794325 21DEC2018
6 12.52319632 55.21446125 26DEC2018
7 12.41659721 56.41302146 21APR2019
8 12.14316592 55.49789875 05JUN2019
9 12.13478134 55.50795469 21DEC2019
;

data Observations_2017;
input Day :date9. Longitude Latitude;
format day date9.;
cards;
01FEB2017 12.21175456 55.14562659
17FEB2017 12.21175456 55.14562659
05MAR2017 12.42293265 56.42302356
12JUN2017 12.06837264 55.21363221
;

data Observations_2018;
input Day :date9. Longitude Latitude;
format day date9.;
cards;
01FEB2018 12.14045456 55.49432659
21FEB2018 12.14052348 55.50925689
05MAR2018 12.53193265 55.21302356
12JUN2018 12.06837264 55.21363221
;

data Observations_2019;
input Day :date9. Longitude Latitude;
format day date9.;
cards;
01FEB2019 12.41615456 55.46532659
21FEB2019 12.15112348 55.48725689
05MAR2019 12.13393265 55.49902356
21DEC2019 12.13637264 55.50263221
;

/* Combine "Observations" datasets */

data obs_allyears;
set observations_20:;
run;

/* Derive the new variables D0_500, D500_1000 and D1000_1500 */

proc sql;
create table want as
select a.*, 
(select count(*) from obs_allyears b where .z&amp;lt;intnx('year',a.day,0)&amp;lt;=b.day&amp;lt;=a.day 
   &amp;amp; 0&amp;lt;=geodist(a.latitude, a.longitude, b.latitude, b.longitude)&amp;lt;=0.5) as d0_500,
(select count(*) from obs_allyears b where .z&amp;lt;intnx('year',a.day,0)&amp;lt;=b.day&amp;lt;=a.day 
   &amp;amp; 0.5&amp;lt;geodist(a.latitude, a.longitude, b.latitude, b.longitude)&amp;lt;=1)  as d500_1000,
(select count(*) from obs_allyears b where .z&amp;lt;intnx('year',a.day,0)&amp;lt;=b.day&amp;lt;=a.day 
   &amp;amp; 1&amp;lt;geodist(a.latitude, a.longitude, b.latitude, b.longitude)&amp;lt;=1.5)  as d1000_1500
from main a;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 23 Apr 2020 20:38:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/641230#M191088</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-04-23T20:38:57Z</dc:date>
    </item>
    <item>
      <title>Re: Generate new difficult variable that count observations based on location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/641586#M191237</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot for your time! It does seem like the GEODIST function could work. I do, however, have some problems. I have with succes made one combined dataset for the three years (here called "obs_allyears). Does the "a.latitude" and "b.latitude" refer to the latitude from the "main_dataset" and from the "obs_allyears" respectively? Or is it the other way around? The same for "a.day" and "b.day". The variables in my real datasets (both the main and the combined) does not have the same name ('day') in both of them, so I'm getting a lot of error-messages.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope to hear from you once again, and thank your a lot!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All best&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2020 12:21:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/641586#M191237</guid>
      <dc:creator>Mikkel_madsen</dc:creator>
      <dc:date>2020-04-21T12:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: Generate new difficult variable that count observations based on location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/641631#M191269</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/324058"&gt;@Mikkel_madsen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Does the "a.latitude" and "b.latitude" refer to the latitude from the "main_dataset" and from the "obs_allyears" respectively?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Exactly. The letter after the table name in the FROM clause (e.g. "... &lt;FONT face="courier new,courier"&gt;from main &lt;STRONG&gt;a&lt;/STRONG&gt;&lt;/FONT&gt;") defines that letter as an &lt;EM&gt;alias&lt;/EM&gt; for the table name. Thus it's possible to distinguish between variables with the same name, but from different tables (i.e. SAS datasets), like &lt;FONT face="courier new,courier"&gt;a.day&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;b.day&lt;/FONT&gt;. Longer aliases or the original table names (without defining aliases) are admissible as well, e.g. &lt;FONT face="courier new,courier"&gt;main.day&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;obs_allyears.day&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/324058"&gt;@Mikkel_madsen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;The variables in my real datasets (both the main and the combined) does not have the same name ('day') in both of them, so I'm getting a lot of error-messages.&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then just use the respective names. If a variable name is unique, you don't need an alias for the distinction. For example, if, say,&amp;nbsp;&lt;FONT face="courier new,courier"&gt;obsdate&lt;/FONT&gt; (rather than &lt;FONT face="courier new,courier"&gt;day&lt;/FONT&gt;) was the date variable in &lt;FONT face="courier new,courier"&gt;obs_allyears&lt;/FONT&gt;, you could simply write&lt;/P&gt;
&lt;PRE&gt;.z&amp;lt;intnx('year',&lt;STRONG&gt;day&lt;/STRONG&gt;,0)&amp;lt;=&lt;STRONG&gt;obsdate&lt;/STRONG&gt;&amp;lt;=&lt;STRONG&gt;day&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;in the WHERE clauses.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(The alias "&lt;FONT face="courier new,courier"&gt;a.&lt;/FONT&gt;" in "&lt;FONT face="courier new,courier"&gt;select a.*&lt;/FONT&gt;" is redundant anyway and could be omitted, because the corresponding FROM clause refers just to a single dataset.)&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 20:40:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/641631#M191269</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-04-23T20:40:04Z</dc:date>
    </item>
    <item>
      <title>Re: Generate new difficult variable that count observations based on location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/641844#M191384</link>
      <description>&lt;P&gt;Thank you for being so kind and helpful&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have changed the variable names with the ones used in the real dataset.&lt;/P&gt;&lt;P&gt;So far so good. Now it look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table Data_komplet_Geo as&lt;BR /&gt;select a.*,&lt;BR /&gt;(select count(*) from Data_komplet b where intnx('year',a.eventtime,0)&amp;lt;=b.Time&amp;lt;=a.eventtime&amp;nbsp;&lt;BR /&gt;&amp;amp; 0&amp;lt;=geodist(a.event_northing, a.event_easting, b.latitude, b.longitude)&amp;lt;=0.5) as d0_500,&lt;BR /&gt;(select count(*) from Data_komplet b where intnx('year',a.eventtime,0)&amp;lt;=b.Time&amp;lt;=a.eventtime&lt;BR /&gt;&amp;amp; 0.5&amp;lt;geodist(a.event_northing, a.event_easting, b.latitude, b.longitude)&amp;lt;=1) as d500_1000,&lt;BR /&gt;(select count(*) from Data_komplet b where intnx('year',a.eventtime,0)&amp;lt;=b.Time&amp;lt;=a.eventtime&lt;BR /&gt;&amp;amp; 1&amp;lt;geodist(a.event_northing, a.event_easting, b.latitude, b.longitude)&amp;lt;=1.5) as d1000_1500&lt;BR /&gt;from Final_database a;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately, I still get a lot of error messages (the following):&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Function GEODIST requires a numeric expression as argument 1.&lt;BR /&gt;ERROR: Function GEODIST requires a numeric expression as argument 2.&lt;BR /&gt;ERROR: Expression using less than or equal (&amp;lt;=) has components that are of different data types.&lt;BR /&gt;ERROR: Function GEODIST requires a numeric expression as argument 1.&lt;BR /&gt;ERROR: Function GEODIST requires a numeric expression as argument 2.&lt;BR /&gt;ERROR: Expression using less than or equal (&amp;lt;=) has components that are of different data types.&lt;BR /&gt;ERROR: Function GEODIST requires a numeric expression as argument 1.&lt;BR /&gt;ERROR: Function GEODIST requires a numeric expression as argument 2.&lt;BR /&gt;ERROR: Expression using less than (&amp;lt;) has components that are of different data types.&lt;BR /&gt;ERROR: Function GEODIST requires a numeric expression as argument 1.&lt;BR /&gt;ERROR: Function GEODIST requires a numeric expression as argument 2.&lt;BR /&gt;ERROR: Expression using less than or equal (&amp;lt;=) has components that are of different data types.&lt;BR /&gt;ERROR: Function GEODIST requires a numeric expression as argument 1.&lt;BR /&gt;ERROR: Function GEODIST requires a numeric expression as argument 2.&lt;BR /&gt;ERROR: Expression using less than (&amp;lt;) has components that are of different data types.&lt;BR /&gt;ERROR: Function GEODIST requires a numeric expression as argument 1.&lt;BR /&gt;ERROR: Function GEODIST requires a numeric expression as argument 2.&lt;BR /&gt;ERROR: Expression using less than or equal (&amp;lt;=) has components that are of different data types.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure exactly why. My 'a.eventtime' is stored as: 14MAY201813:15:10 (May 14th 2018, with the last 13:15:10 being time of day, in hours:min:sec). My 'b.Time' is stored as: 30DEC1716:31:00 (again, December 30th 2017 at 16:31:00 in hour:min:sec). So there is a difference in how the year is stored (2018 vs just 17). Is that the problem? Or maybe the time of day (the hour:min:sec)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your patience.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2020 08:27:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/641844#M191384</guid>
      <dc:creator>Mikkel_madsen</dc:creator>
      <dc:date>2020-04-22T08:27:35Z</dc:date>
    </item>
    <item>
      <title>Re: Generate new difficult variable that count observations based on location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/641864#M191397</link>
      <description>&lt;P&gt;You're welcome.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error messages clearly indicate that&amp;nbsp;&lt;FONT face="courier new,courier"&gt;event_northing&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;event_easting&lt;/FONT&gt; are &lt;EM&gt;character&lt;/EM&gt; variables, whereas the GEODIST function requires &lt;EM&gt;numeric&lt;/EM&gt; arguments. You could do the conversion "on the fly" in the PROC SQL step by replacing&amp;nbsp;&lt;FONT face="courier new,courier"&gt;a.event_northing&lt;/FONT&gt; by &lt;FONT face="courier new,courier"&gt;input(event_northing, 32.)&lt;/FONT&gt;and similarly for &lt;FONT face="courier new,courier"&gt;a.event_easting&lt;/FONT&gt;. (As mentioned earlier, you don't need the aliases since there are no name conflicts.) But I would rather create the two new numeric variables in a preliminary step as shown in the example below and&amp;nbsp;use the newly created dataset in the PROC SQL step (i.e., &lt;FONT face="courier new,courier"&gt;Ultimate_database&lt;/FONT&gt; in place of &lt;FONT face="courier new,courier"&gt;Final_database&lt;/FONT&gt;). If &lt;FONT face="courier new,courier"&gt;Final_database&lt;/FONT&gt; is a huge dataset that you wouldn't want to duplicate just for the sake of a variable conversion, we can discuss other options.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create test data */

data Final_database;
input ID event_northing :$20. event_easting :$20. Day :date9.;
format day date9.;
cards;
1 12.21236548 55.14578965 15FEB2017
;

/* Create numeric variables for northing and easting */

data Ultimate_database;
set Final_database(rename=(event_northing=event_northing_char event_easting=event_easting_char));
event_northing=input(event_northing_char, 32.);
event_easting=input(event_easting_char, 32.);
drop event_northing_char event_easting_char; /* &amp;lt;-- optional: remove the character versions */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Similar considerations apply to the &lt;FONT face="courier new,courier"&gt;Time&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;eventtime&lt;/FONT&gt; variables. The latter could be converted in the above DATA step, the former in the DATA step creating&amp;nbsp;&lt;SPAN&gt;&lt;FONT face="courier new,courier"&gt;Data_komplet&lt;/FONT&gt;. The details of the datetime conversions depend on the variable types of&amp;nbsp;&lt;FONT face="courier new,courier"&gt;Time&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;eventtime&lt;/FONT&gt;&amp;nbsp;(i.e., character or numeric, please see PROC CONTENTS output of the corresponding datasets) and, if numeric, on the kind of values.&amp;nbsp;Moreover, the first argument of the INTNX function calls must be changed to &lt;FONT face="courier new,courier"&gt;'&lt;STRONG&gt;dt&lt;/STRONG&gt;year'&lt;/FONT&gt; if the second argument is a SAS datetime, not a SAS date.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2020 09:35:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/641864#M191397</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-04-22T09:35:27Z</dc:date>
    </item>
    <item>
      <title>Re: Generate new difficult variable that count observations based on location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/641914#M191421</link>
      <description>&lt;P&gt;It seems like that converting 'on the fly' with input(event_norting,32.) and input(event_easting,32.) solved the problem! The program runs without any errors now, so I guess there is no problem with the dates.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;. I would have been stuck for weeks without your quick help! Hope I may continue this thread should I encounter other problems in relation to this topic.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have a nice day.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2020 12:59:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/641914#M191421</guid>
      <dc:creator>Mikkel_madsen</dc:creator>
      <dc:date>2020-04-22T12:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: Generate new difficult variable that count observations based on location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/641961#M191442</link>
      <description>&lt;P&gt;Glad to hear that my suggestions worked for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think each of the following conditions must be met so that indeed "&lt;SPAN&gt;there is no problem with the dates." I would definitely check this.&lt;/SPAN&gt;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;SPAN&gt;Both &lt;FONT face="courier new,courier"&gt;Time&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;eventtime&lt;/FONT&gt; are &lt;EM&gt;numeric&lt;/EM&gt; variables in their respective datasets.&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;When you saw human readable values such as&amp;nbsp;14MAY2018:13:15:10 (typically with a colon or a "T" between year and hour), you applied a format suitable for SAS datetime values, e.g. &lt;FONT face="courier new,courier"&gt;datetime19.&lt;/FONT&gt;. Most likely, the format would be permanently associated with the&amp;nbsp;&amp;nbsp;&lt;FONT face="courier new,courier"&gt;Time&lt;/FONT&gt;&amp;nbsp;or&amp;nbsp;&lt;FONT face="courier new,courier"&gt;eventtime&lt;/FONT&gt;&amp;nbsp;variable (see PROC CONTENTS output).&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;&lt;SPAN&gt;Typical &lt;EM&gt;un&lt;/EM&gt;formatted values of these variables are about 1,800,000,000 for datetimes from 2017-2019, because&amp;nbsp;&lt;FONT face="courier new,courier"&gt;'01JAN2017:00:00'dt=1798848000&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;'01JAN2020:00:00'dt=1893456000&lt;/FONT&gt;. You can check these values with PROC MEANS, e.g.:&lt;BR /&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=Data_komplet min median max;
var Time;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;SPAN&gt;(and similarly for the other dataset).&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;SPAN&gt;You used &lt;FONT face="courier new,courier"&gt;'dtyear'&lt;/FONT&gt;, not &lt;FONT face="courier new,courier"&gt;'year'&lt;/FONT&gt; as the time interval in the INTNX function calls, as I suggested.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And, yes, of course, feel free to ask if new questions arise (which are so close to the topic of the current thread that opening a new one would seem inappropriate).&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2020 14:24:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/641961#M191442</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-04-22T14:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: Generate new difficult variable that count observations based on location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/642358#M191599</link>
      <description>&lt;P&gt;Hi again&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have checked the following and can add:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) When I look in the original datasets (Data_komplet and Final_database), the 'eventtime' (from Final_database) is numeric with the format &lt;EM&gt;datetime19.&lt;/EM&gt; while the 'time' (from Data_komplet) is numeric with the format &lt;EM&gt;datetime18.&amp;nbsp;&lt;/EM&gt;(I rightclick on the variable name and press 'properties' where the type and format e.g. numeric and datetime19. is shown. The same is found when using PROC CONTETNS).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is that ok? Or should 'time' and 'eventtime' have the same format (e.g. datetime19. or datetime18.)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) In both datasets I see human readable values (in Data_komplet e.g. 12MAY0714:40:00 and in Final_database e.g. 01JUN2018:10:46:45 - that is, there is a difference the datasets between with a "missing" colon between the year and time in Data_komplet and a "missing" 20 in year in Data_komplet. I am not sure whether this will hinder analyses.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3) In Final_database the median is 1838539767 while the median in Data_komplet is 1789633440 (though I guess this is because I have observations older than 2017 in the Data_komplet dataset e.g. from 2007).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4) I changed the 'year' to 'dtyear' it did, however, result in a significant drop in observations in d0_500, d500_1000, and d1000_1500 ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know I must sound a bit confused, but I'm very thankful for your enormous help! I might have some extra questions and wishes to the program, but I will focuse on the problems above first. Once again, thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 18:23:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/642358#M191599</guid>
      <dc:creator>Mikkel_madsen</dc:creator>
      <dc:date>2020-04-23T18:23:50Z</dc:date>
    </item>
    <item>
      <title>Re: Generate new difficult variable that count observations based on location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/642404#M191628</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/324058"&gt;@Mikkel_madsen&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for checking. Here are my comments on items 1 - 4:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Numeric is good. Formats have no impact on calculations (because SAS uses the internal values), so the (minor) difference between &lt;FONT face="courier new,courier"&gt;datetime19.&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;datetime18.&lt;/FONT&gt; is irrelevant for our purposes.&lt;/LI&gt;
&lt;LI&gt;The formats produce the human-readable values. I'm surprised about the missing colon between date and time in your reported &lt;FONT face="courier new,courier"&gt;datetime18.&lt;/FONT&gt; value. This omission does not occur with my SAS 9.4 and I have never seen this before. Nevertheless, it would be irrelevant for the analysis.&lt;/LI&gt;
&lt;LI&gt;These median values look plausible. Make sure that this is true for the extreme values (minimum and maximum) as well, i.e., no datetime values from, say, 1960 or 2099 due to data errors.&lt;/LI&gt;
&lt;LI&gt;Well done! The higher numbers in &lt;FONT face="courier new,courier"&gt;d0_500&lt;/FONT&gt; etc. obtained with &lt;FONT face="courier new,courier"&gt;'year'&lt;/FONT&gt; must have been plain wrong! See the example and further explanations below.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input dt;
dt0=intnx('dtyear',dt,0); /* correct */
dtx=intnx('year',dt,0); /* incorrect */
cards;
1838539767
.
;

proc print data=test;
format dt: datetime18.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log of the DATA step:&lt;/P&gt;
&lt;PRE&gt;1164  data test;
1165  input dt;
1166  dt0=intnx('dtyear',dt,0); /* correct */
1167  dtx=intnx('year',dt,0); /* incorrect */
1168  cards;

&lt;FONT color="#0000FF"&gt;NOTE: Invalid argument to function INTNX('year',1838539767,0) at line 1167 column 5.&lt;/FONT&gt;
RULE:       ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
1169        1838539767
dt=1838539767 dt0=1830384000 dtx=. _ERROR_=1 _N_=1
&lt;FONT color="#0000FF"&gt;NOTE: Missing values were generated as a result of performing an operation on missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      1 at 1166:5   1 at 1167:5
NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      1 at 1167:5
NOTE: The data set WORK.TEST has 2 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;The invalid combination of &lt;FONT face="courier new,courier"&gt;'year'&lt;/FONT&gt; in the first and a datetime value (more precisely: a value too large for a SAS &lt;EM&gt;date&lt;/EM&gt; value) in the second argument of INTNX causes the first and the third note in the log and also the black text between the first and the second note. The second note is triggered by the missing value in the second observation, which I added for demonstration.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output of PROC PRINT (btw, note the colon between date and time):&lt;/P&gt;
&lt;PRE&gt;Obs                    dt                   dt0                   dtx

 1       05APR18:09:29:27      01JAN18:00:00:00                     .
 2                      .                     .                     .&lt;/PRE&gt;
&lt;P&gt;The incorrect interval specification &lt;FONT face="courier new,courier"&gt;'year'&lt;/FONT&gt; leads to a missing value of &lt;FONT face="courier new,courier"&gt;dtx&lt;/FONT&gt;, as does (less surprisingly) the missing value in &lt;FONT face="courier new,courier"&gt;dt&lt;/FONT&gt; itself, whereas &lt;FONT face="courier new,courier"&gt;dt0&lt;/FONT&gt; contains the intended start-of-the-year datetime value for non-missing &lt;FONT face="courier new,courier"&gt;dt&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC SQL tends to be less verbose in terms of relevant log messages:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select intnx('dtyear',dt,0) as dt0,
       intnx('year',dt,0)   as dtx
from test;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;1176  proc sql;
1177  select intnx('dtyear',dt,0) as dt0,
1178         intnx('year',dt,0)   as dtx
1179  from test;
&lt;FONT color="#0000FF"&gt;NOTE: Invalid argument to function INTNX. Missing values may be generated.
NOTE: Invalid (or missing) arguments to the INTNX function have caused the function to return a missing value.&lt;/FONT&gt;
1180  quit;
&lt;FONT color="#0000FF"&gt;NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;Only a one-line note for each of the two issues.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, a WHERE clause in PROC SQL or likewise a WHERE statement in a DATA step or a WHERE= dataset option do not write any suspicious note about these data/code issues to the log!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sel;
set test;
where intnx('year',dt,0)&amp;lt;='01JAN2017:00:00'dt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;1181  data sel;
1182  set test;
1183  where intnx('year',dt,0)&amp;lt;='01JAN2017:00:00'dt;
1184  run;

&lt;FONT color="#0000FF"&gt;NOTE: There were 2 observations read from the data set WORK.TEST.
      WHERE INTNX('year', dt, 0)&amp;lt;='  01JAN2017:00:00:00'DT;
NOTE: The data set WORK.SEL has 2 observations and 3 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;Both observations satisfy the WHERE condition, because in both cases&amp;nbsp;&lt;FONT face="courier new,courier"&gt;intnx('year',dt,0)&lt;/FONT&gt; results in a missing value and missing values are considered smaller than non-missing values. With the correct &lt;FONT face="courier new,courier"&gt;'dtyear'&lt;/FONT&gt; the first observation (the datetime from 2018) would clearly not have been selected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, with the incorrect&amp;nbsp;&lt;FONT face="courier new,courier"&gt;'year'&lt;/FONT&gt; interval the first part of the WHERE condition in your program (the first "&amp;lt;=" inequality) was effectively &lt;EM&gt;deactivated&lt;/EM&gt; (namely&amp;nbsp;&lt;EM&gt;always&lt;/EM&gt; true, regardless of the datetime values), hence the additional counts in &lt;FONT face="courier new,courier"&gt;d0_500&lt;/FONT&gt; etc. It's always shocking to see how such mistakes can corrupt results &lt;EM&gt;while the SAS log is clean&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a precaution it is advisable to exclude missing values in WHERE or IF conditions on the "less than" side of comparison operators. In your example:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;... where &lt;STRONG&gt;&lt;FONT color="#00CCFF"&gt;.z&amp;lt;&lt;/FONT&gt;&lt;/STRONG&gt;intnx('dtyear',a.eventtime,0)&amp;lt;=b.Time&amp;lt;=a.eventtime ...&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;(using the largest special missing value &lt;FONT face="courier new,courier"&gt;.z&lt;/FONT&gt;, but in most situations the ordinary missing value &lt;FONT face="courier new,courier"&gt;.&lt;/FONT&gt; would be sufficient). This would also prevent the WHERE condition from being satisfied if both of the two datetime values were missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have inserted the "&lt;FONT face="courier new,courier"&gt;.z&amp;lt;&lt;/FONT&gt;" into my earlier posts of this thread in order to demonstrate this defensive programming style, also to later readers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Apr 2020 21:14:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/642404#M191628</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-04-23T21:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: Generate new difficult variable that count observations based on location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/642623#M191737</link>
      <description>&lt;P&gt;Hi again&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your thorough walkthrough, I think that I can follow however, it's a bit complicated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I guess that everything works correctly now. I'm using SAS Enterprise Guide v. 9.1, maybe that's why there's a missing colon in the dates? However, if it does not matte for the analysis to be done correctly then I guess it's okay anyway.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have also inserted the ".&amp;lt;z" in the program.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your kindness and help! Have a nice weekend!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Apr 2020 14:53:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/642623#M191737</guid>
      <dc:creator>Mikkel_madsen</dc:creator>
      <dc:date>2020-04-24T14:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: Generate new difficult variable that count observations based on location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/664227#M198399</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope you are well and that I might may request some further help from you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;You helped me generate this programme:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
create table Data_komplet_Geo as
select a.*, 
(select count(*) from Data_komplet b where .z&amp;lt;intnx('dtyear',a.eventtime,0)&amp;lt;=b.createdtime&amp;lt;=a.eventtime 
   &amp;amp; 0&amp;lt;=geodist(input(event_northing,32.), input(event_easting,32.), b.latitude, b.longitude)&amp;lt;=0.360) as d0_360,
(select count(*) from Data_komplet b where .z&amp;lt;intnx('dtyear',a.eventtime,0)&amp;lt;=b.createdtime&amp;lt;=a.eventtime
   &amp;amp; 0.360&amp;lt;geodist(input(event_northing,32.), input(event_easting,32.), b.latitude, b.longitude)&amp;lt;=1.08)  as d360_1080,
(select count(*) from Data_komplet b where .z&amp;lt;intnx('dtyear',a.eventtime,0)&amp;lt;=b.createdtime&amp;lt;=a.eventtime
   &amp;amp; 1.08&amp;lt;geodist(input(event_northing,32.), input(event_easting,32.), b.latitude, b.longitude)&amp;lt;=1.8)  as d1080_1800
from Final_database a;
quit;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It worked well, but unfortunately I would like some more. You might remember my two datasets "Final_database" and the three datasets I joined to "Data_komplet". They looked like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Final_database:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp;Longitude&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Lattitude&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Eventtime&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;12.21236548&amp;nbsp; &amp;nbsp; &amp;nbsp;55.14578965&amp;nbsp; &amp;nbsp; &amp;nbsp;15FEB201713:15:10&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;12.52319752&amp;nbsp; &amp;nbsp; &amp;nbsp;55.21460198&amp;nbsp; &amp;nbsp; &amp;nbsp;19FEB201717:12:10&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;12.41219754&amp;nbsp; &amp;nbsp; &amp;nbsp;56.41301547&amp;nbsp; &amp;nbsp; &amp;nbsp;21APR201711:03:11&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp;12.14016597&amp;nbsp; &amp;nbsp; &amp;nbsp;55.49783265&amp;nbsp; &amp;nbsp; &amp;nbsp;05JUN201808:05:44&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp;12.13497326&amp;nbsp; &amp;nbsp; &amp;nbsp;55.65794325&amp;nbsp; &amp;nbsp; &amp;nbsp;21DEC201815:59:44&lt;/P&gt;&lt;P&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp;12.52319632&amp;nbsp; &amp;nbsp; &amp;nbsp;55.21446125&amp;nbsp; &amp;nbsp; &amp;nbsp;26DEC201806:30:12&lt;/P&gt;&lt;P&gt;7&amp;nbsp; &amp;nbsp; &amp;nbsp;12.41659721&amp;nbsp; &amp;nbsp; &amp;nbsp;56.41302146&amp;nbsp; &amp;nbsp; &amp;nbsp;21APR201922:12:42&lt;/P&gt;&lt;P&gt;8&amp;nbsp; &amp;nbsp; &amp;nbsp;12.14316592&amp;nbsp; &amp;nbsp; &amp;nbsp;55.49789875&amp;nbsp; &amp;nbsp; &amp;nbsp;05JUN201902:22:23&lt;/P&gt;&lt;P&gt;9&amp;nbsp; &amp;nbsp; &amp;nbsp;12.13478134&amp;nbsp; &amp;nbsp; &amp;nbsp;55.65795469&amp;nbsp; &amp;nbsp; &amp;nbsp;21DEC2019&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data_komplet:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Createdtime&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Longitude&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Lattitude&lt;/P&gt;&lt;P&gt;01FEB1712:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp;12.62315456&amp;nbsp; &amp;nbsp; &amp;nbsp;55.46532659&lt;/P&gt;&lt;P&gt;21FEB1708:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp;12.65312348&amp;nbsp; &amp;nbsp; &amp;nbsp;55.64325689&lt;/P&gt;&lt;P&gt;05MAR1709:00:00&amp;nbsp; &amp;nbsp; 12.54693265&amp;nbsp; &amp;nbsp; &amp;nbsp;55.21302356&lt;/P&gt;&lt;P&gt;12JUN1712:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp;12.06837264&amp;nbsp; &amp;nbsp; &amp;nbsp;55.21363221&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My 'Data_komplet' database have changed a bit to:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Var&amp;nbsp; &amp;nbsp; Createdtime&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Longitude&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Lattitude&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Type&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Open&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Close&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 24/7&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 01FEB1712:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp;12.62315456&amp;nbsp; &amp;nbsp; &amp;nbsp;55.46532659&amp;nbsp; &amp;nbsp; &amp;nbsp;Monday&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;08:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp;22:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 01FEB1712:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp;12.62315456&amp;nbsp; &amp;nbsp; &amp;nbsp;55.46532659&amp;nbsp; &amp;nbsp; &amp;nbsp;Tuesday&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 08:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp;22:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 01FEB1712:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp;12.62315456&amp;nbsp; &amp;nbsp; &amp;nbsp;55.46532659&amp;nbsp; &amp;nbsp; &amp;nbsp;Wednesday&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 08:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp;22:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 01FEB1712:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp;12.62315456&amp;nbsp; &amp;nbsp; &amp;nbsp;55.46532659&amp;nbsp; &amp;nbsp; &amp;nbsp;Thursday&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;08:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp;22:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 01FEB1712:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp;12.62315456&amp;nbsp; &amp;nbsp; &amp;nbsp;55.46532659&amp;nbsp; &amp;nbsp; &amp;nbsp;Friday&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;08:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp;22:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 21FEB1708:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp;12.65312348&amp;nbsp; &amp;nbsp; &amp;nbsp;55.64325689&amp;nbsp; &amp;nbsp; &amp;nbsp;Monday&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp;22:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 21FEB1708:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp;12.65312348&amp;nbsp; &amp;nbsp; &amp;nbsp;55.64325689&amp;nbsp; &amp;nbsp; &amp;nbsp;Tuesday&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;08:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp;22:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 21FEB1708:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp;12.65312348&amp;nbsp; &amp;nbsp; &amp;nbsp;55.64325689&amp;nbsp; &amp;nbsp; &amp;nbsp;Wednesday&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp;22:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; 21FEB1708:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp;12.65312348&amp;nbsp; &amp;nbsp; &amp;nbsp;55.64325689&amp;nbsp; &amp;nbsp; &amp;nbsp;Thursday&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;08:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp;22:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; N&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; 05MAR1709:00:00&amp;nbsp; &amp;nbsp; 12.54693265&amp;nbsp; &amp;nbsp; &amp;nbsp;55.21302356&amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; 12JUN1712:00:00&amp;nbsp; &amp;nbsp; &amp;nbsp;12.06837264&amp;nbsp; &amp;nbsp; &amp;nbsp;55.21363221&amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So... The objective is the same: to count how many observations from 'Data_komplet' that lies within 0-360, 360-1080 and 1080-1800 meters from the observations in 'Final_database'. But it should only count those where eventtime &amp;lt;= createdtime. Further, it should only count those observations from 'Data_komplet' that are either 24/7 (in the first 'Data_komplet' where you helped me, all observations where 24/7) or those where the day in 'Type' matches the weekday of 'Eventtime' and where the time (from 'eventtime') is within the openinghours (between 'Open' and 'Close').&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Phew. A bit complicated to explain! Hope that it is clear and that you have a suggestion - if it is possible!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All best,&lt;/P&gt;&lt;P&gt;MM&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jun 2020 10:00:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/664227#M198399</guid>
      <dc:creator>Mikkel_madsen</dc:creator>
      <dc:date>2020-06-23T10:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: Generate new difficult variable that count observations based on location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/664286#M198421</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/324058"&gt;@Mikkel_madsen&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/324058"&gt;@Mikkel_madsen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;So... The objective is the same: to count how many observations from 'Data_komplet' that lies within 0-360, 360-1080 and 1080-1800 meters from the observations in 'Final_database'. But it should only count those where &lt;FONT color="#808000"&gt;eventtime &amp;lt;= createdtime&lt;/FONT&gt;. Further, it should only count those observations from 'Data_komplet' that are &lt;FONT color="#FF6600"&gt;either 24/7&lt;/FONT&gt; (in the first 'Data_komplet' where you helped me, all observations where 24/7) &lt;FONT color="#FF6600"&gt;or&lt;/FONT&gt; those where the &lt;FONT color="#00CCFF"&gt;day in 'Type' matches the weekday of 'Eventtime'&lt;/FONT&gt; &lt;FONT color="#993366"&gt;and where the time (from 'eventtime') is within the openinghours (between 'Open' and 'Close')&lt;/FONT&gt;.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So you'll need to modify the WHERE conditions to something like the example below (and analogously for the other two distance ranges):&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#808000"&gt;&lt;STRONG&gt;  .z&amp;lt;a.eventtime&amp;lt;=b.createdtime&lt;/STRONG&gt;&lt;/FONT&gt;
&amp;amp; 0.360&amp;lt;geodist(input(event_northing,32.), input(event_easting,32.), b.latitude, b.longitude)&amp;lt;=1.08)
&amp;amp; (&lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;b.f247='Y' |&lt;/FONT&gt; &lt;FONT color="#00CCFF"&gt;put(datepart(a.eventtime),downame.-l)=left(b.type)&lt;/FONT&gt; &lt;FONT color="#993366"&gt;&amp;amp; b.open&amp;lt;=timepart(a.eventtime)&amp;lt;=b.close&lt;/FONT&gt;&lt;/STRONG&gt;)&lt;/PRE&gt;
&lt;P&gt;The second line (check of the distance) is unchanged. The modified first line reflects your new criterion, which does no longer require &lt;FONT face="courier new,courier"&gt;eventtime&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;createdtime&lt;/FONT&gt; to be in the same year (i.e., now an event in, say, 2016 would also meet the condition with&amp;nbsp;&lt;FONT face="courier new,courier"&gt;createdtime&lt;/FONT&gt; values in 2017, 2018, etc.).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The newly added third line contains the new criteria regarding "24/7" and opening hours/weekday. However, this part might need to be changed depending on your data structure:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Most likely, the real name of the "24/7" flag variable is not &lt;FONT face="courier new,courier"&gt;f247&lt;/FONT&gt; (which is what I used as an example), so please change it correspondingly. Note that "24/7" is not a valid SAS variable name. Possibly the name is&amp;nbsp;&lt;FONT face="courier new,courier"&gt;'24/7'n&lt;/FONT&gt;, but I would not recommend using these (so called) name literals. It's not even clear from your post whether this is a character variable or perhaps a formatted numeric variable (like 0='N', 1='Y'), which would require a different WHERE condition.&lt;/LI&gt;
&lt;LI&gt;Similar ambiguities exist for variable &lt;FONT face="courier new,courier"&gt;Type&lt;/FONT&gt;. The code above assumes a character variable &lt;FONT face="courier new,courier"&gt;Type&lt;/FONT&gt; containing values like those shown in your post.&lt;/LI&gt;
&lt;LI&gt;Also the last part of the condition involves an assumption I had to make: that variables &lt;FONT face="courier new,courier"&gt;Open&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;Close&lt;/FONT&gt; are numeric and contain SAS time values, i.e., numbers of seconds after midnight. If they were character variables (containing values like '08:00:00'), you would convert them "on the fly" like&amp;nbsp;&lt;FONT face="courier new,courier"&gt;input(b.open,time8.)&lt;/FONT&gt;&amp;nbsp;instead of &lt;FONT face="courier new,courier"&gt;b.open&lt;/FONT&gt; etc.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Note further that the incomplete &lt;FONT face="courier new,courier"&gt;eventtime&lt;/FONT&gt; value shown for ID 9 ("&lt;SPAN&gt;21DEC2019") cannot exist in a SAS datetime variable.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Jun 2020 13:48:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/664286#M198421</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-06-23T13:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: Generate new difficult variable that count observations based on location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/664911#M198708</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for always being so helpful and kind!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I made a mistake with the createdtime and eventtime. It should only (as in the first programme) count eventtimes that took places&amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;after&lt;/STRONG&gt;&lt;/EM&gt; createdtime - so I left the first line unchanged (as in the old programme).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have checked my variables:&lt;/P&gt;&lt;P&gt;1) The variable "247" (which is the correct name of the variable) is a yes/no character variable (in the format "$CHAR3.).&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) The "Type" variable is also a character variable (in the format $CHAR9.). The values in the "Type" variable is the seven different weekdays (e.g. Monday, tuesday etc.).&amp;nbsp;&lt;/P&gt;&lt;P&gt;3) The variables "Open" and "Close" are both numeric variables with the format TIME8. and the informat TIME11.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does it require any adjustments?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again! Have a nice day &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All best MM&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 08:43:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/664911#M198708</guid>
      <dc:creator>Mikkel_madsen</dc:creator>
      <dc:date>2020-06-25T08:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: Generate new difficult variable that count observations based on location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/664953#M198730</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/324058"&gt;@Mikkel_madsen&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You're welcome.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/324058"&gt;@Mikkel_madsen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have checked my variables:&lt;/P&gt;
&lt;P&gt;1) The variable "247" (which is the correct name of the variable) is a yes/no character variable (in the format "$CHAR3.).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) The "Type" variable is also a character variable (in the format $CHAR9.). The values in the "Type" variable is the seven different weekdays (e.g. Monday, tuesday etc.).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3) The variables "Open" and "Close" are both numeric variables with the format TIME8. and the informat TIME11.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does it require any adjustments?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;1) Only a name literal such as &lt;FONT face="courier new,courier"&gt;"247"n&lt;/FONT&gt;&amp;nbsp;can start with a digit (but it's displayed without the quotes and the &lt;FONT face="courier new,courier"&gt;n&lt;/FONT&gt;). If this is the name of the variable and it has length 3 (see format length) because it contains values &lt;FONT face="courier new,courier"&gt;'Yes'&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;'No'&lt;/FONT&gt; (rather than &lt;FONT face="courier new,courier"&gt;'Y'&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;'N'&lt;/FONT&gt;), then, of course, the pertinent condition needs to be modified: Instead of&lt;/P&gt;
&lt;PRE&gt;b.f247='Y'&lt;/PRE&gt;
&lt;P&gt;you could use&lt;/P&gt;
&lt;PRE&gt;upcase(b.'247'n) eqt 'Y'&lt;/PRE&gt;
&lt;P&gt;This would work with values &lt;FONT face="courier new,courier"&gt;'Yes'&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;'yes'&lt;/FONT&gt;, &lt;FONT face="courier new,courier"&gt;'YES'&lt;/FONT&gt;,&amp;nbsp;&lt;FONT face="courier new,courier"&gt;'Y'&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;'y'&lt;/FONT&gt; (left aligned in case of single characters; otherwise add the LEFT function), even with &lt;FONT face="courier new,courier"&gt;'yep'&lt;/FONT&gt; etc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) The weekday criterion I proposed is case sensitive, i.e., &lt;FONT face="courier new,courier"&gt;'Tuesday'&lt;/FONT&gt; would match, but not &lt;FONT face="courier new,courier"&gt;'tuesday'&lt;/FONT&gt; or &lt;FONT face="courier new,courier"&gt;'TUESDAY'&lt;/FONT&gt;. To be on the safe side, you may want to add the UPCASE function to both sides of the condition:&lt;/P&gt;
&lt;PRE&gt;&lt;STRONG&gt;upcase(&lt;/STRONG&gt;put(datepart(a.eventtime),downame.-l)&lt;STRONG&gt;)&lt;/STRONG&gt;=&lt;STRONG&gt;upcase(&lt;/STRONG&gt;left(b.type)&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;3) The time variable metadata look good.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jun 2020 11:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/664953#M198730</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-06-25T11:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: Generate new difficult variable that count observations based on location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/665274#M198891</link>
      <description>&lt;P&gt;Thank you,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The programme now looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
create table Data_komplet_Geo as
select a.*, 
(select count(*) from Data_komplet b where .z&amp;lt;intnx('dtyear',a.eventtime,0)&amp;lt;=b.createdtime&amp;lt;=a.eventtime 
   &amp;amp; 0&amp;lt;=geodist(input(incident_northing,32.), input(incident_easting,32.), b.latitude, b.longitude)&amp;lt;=0.360) 
   &amp;amp; (upcase(left(b.'247'n)) eqt Y | upcase(put(datepart(a.eventtime),downame.-l))=upcase(left(b.Type)) &amp;amp; b.'open'n&amp;lt;=timepart(a.eventtime)&amp;lt;=b.'close'n) as d0_360,
(select count(*) from Data_komplet  b where .z&amp;lt;intnx('dtyear',a.eventtime,0)&amp;lt;=b.createdtime&amp;lt;=a.eventtime
   &amp;amp; 0.360&amp;lt;geodist(input(incident_northing,32.), input(incident_easting,32.), b.latitude, b.longitude)&amp;lt;=1.08)  
   &amp;amp; (upcase(left(b.'247'n)) eqt Y | upcase(put(datepart(a.eventtime),downame.-l))=upcase(left(b.Type)) &amp;amp; b.'open'n&amp;lt;=timepart(a.eventtime)&amp;lt;=b.'close'n) as d360_1080,
(select count(*) from Data_komplet  b where .z&amp;lt;intnx('dtyear',a.eventtime,0)&amp;lt;=b.createdtime&amp;lt;=a.eventtime
   &amp;amp; 1.08&amp;lt;geodist(input(incident_northing,32.), input(incident_easting,32.), b.latitude, b.longitude)&amp;lt;=1.8)  
   &amp;amp; (upcase(left(b.'247'n)) eqt Y | upcase(put(datepart(a.eventtime),downame.-l))=upcase(left(b.Type)) &amp;amp; b.'open'n&amp;lt;=timepart(a.eventtime)&amp;lt;=b.'close'n) as d1080_1800
from Final_database a;
quit;&lt;/PRE&gt;&lt;P&gt;I do however get a number of errors:&lt;/P&gt;&lt;P&gt;ERROR: Unresolved reference to table/correlation name b.&lt;BR /&gt;ERROR: Unresolved reference to table/correlation name b.&lt;BR /&gt;ERROR: Unresolved reference to table/correlation name b.&lt;BR /&gt;ERROR: Unresolved reference to table/correlation name b.&lt;BR /&gt;ERROR: Unresolved reference to table/correlation name b.&lt;BR /&gt;ERROR: Unresolved reference to table/correlation name b.&lt;BR /&gt;ERROR: Unresolved reference to table/correlation name b.&lt;BR /&gt;ERROR: Unresolved reference to table/correlation name b.&lt;BR /&gt;ERROR: Unresolved reference to table/correlation name b.&lt;BR /&gt;ERROR: Unresolved reference to table/correlation name b.&lt;BR /&gt;ERROR: Unresolved reference to table/correlation name b.&lt;BR /&gt;ERROR: Unresolved reference to table/correlation name b.&lt;BR /&gt;ERROR: Expression using less than or equal (&amp;lt;=) has components that are of different data types.&lt;/P&gt;&lt;P&gt;ERROR: Expression using less than or equal (&amp;lt;=) has components that are of different data types.&lt;BR /&gt;ERROR: Expression using less than or equal (&amp;lt;=) has components that are of different data types.&lt;BR /&gt;ERROR: The following columns were not found in the contributing tables: Y.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The affected code is: "from Final_database a;"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What am I not doing right?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks once again.... You do deserve a bottle of wine or something! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All best MM&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2020 08:20:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/665274#M198891</guid>
      <dc:creator>Mikkel_madsen</dc:creator>
      <dc:date>2020-06-26T08:20:06Z</dc:date>
    </item>
    <item>
      <title>Re: Generate new difficult variable that count observations based on location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/665348#M198933</link>
      <description>&lt;P&gt;I found these issues:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The closing parenthesis after &lt;FONT face="courier new,courier"&gt;0.360&lt;/FONT&gt;&amp;nbsp;must be moved to the end of the subquery, i.e., you need &lt;EM&gt;two&lt;/EM&gt; closing parentheses before &lt;FONT face="courier new,courier"&gt;as d0_360&lt;/FONT&gt;. Of course, the other two subqueries need the same correction. Apparently, this was an &lt;EM&gt;unbalanced&lt;/EM&gt; and unnecessary parenthesis in my (untested) suggested WHERE condition. Sorry for that.&lt;/LI&gt;
&lt;LI&gt;You forgot the quotation marks around the string &lt;FONT face="courier new,courier"&gt;Y&lt;/FONT&gt;, so SAS interpreted this as a variable name. Hence the error message "&lt;FONT face="courier new,courier"&gt;columns were not found&lt;/FONT&gt;."&lt;/LI&gt;
&lt;LI&gt;Interesting: I encountered severe error messages such as
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;ERROR: An exception has been encountered.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Please contact technical support and provide them with the following traceback information:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;The SAS task name is [SQL]&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;ERROR: Read Access Violation SQL&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Exception occurred at (0D1D4752)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Task Traceback&lt;/FONT&gt;&lt;BR /&gt;which I could resolve by avoiding the &lt;FONT face="courier new,courier"&gt;-l&lt;/FONT&gt; modifier in the format specification &lt;FONT face="courier new,courier"&gt;downame.-l&lt;/FONT&gt;!&lt;BR /&gt;Do you have a similar problem after correcting the other issues? Then this might be a bug in PROC SQL (!). The&amp;nbsp;&lt;FONT face="courier new,courier"&gt;-l&lt;/FONT&gt; modifier works well in other PROC SQL code I've tested.&lt;BR /&gt;In any case, I would simply use the LEFT function instead (see code below).&lt;/P&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;The variable names &lt;FONT face="courier new,courier"&gt;incident_northing&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;incident_easting&lt;/FONT&gt; have never occurred in sample data you provided. I assume they are from dataset &lt;FONT face="courier new,courier"&gt;Final_database&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just a simplification: There's no need for using name literals with the valid variable names&amp;nbsp;&lt;FONT face="courier new,courier"&gt;open&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;close&lt;/FONT&gt;. (i.e., &lt;FONT face="courier new,courier"&gt;b.open&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;b.close&lt;/FONT&gt; or even &lt;FONT face="courier new,courier"&gt;open&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;close&lt;/FONT&gt; would be sufficient).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table Data_komplet_Geo as
select a.*, 
(select count(*) from Data_komplet b where .z&amp;lt;intnx('dtyear',a.eventtime,0)&amp;lt;=b.createdtime&amp;lt;=a.eventtime 
   &amp;amp; 0&amp;lt;=geodist(input(incident_northing,32.), input(incident_easting,32.), b.latitude, b.longitude)&amp;lt;=0.360 
   &amp;amp; (upcase(left(b.'247'n)) eqt 'Y' | upcase(left(put(datepart(a.eventtime),downame.)))=upcase(left(b.Type)) &amp;amp; b.open&amp;lt;=timepart(a.eventtime)&amp;lt;=b.close)) as d0_360,
(select count(*) from Data_komplet  b where .z&amp;lt;intnx('dtyear',a.eventtime,0)&amp;lt;=b.createdtime&amp;lt;=a.eventtime
   &amp;amp; 0.360&amp;lt;geodist(input(incident_northing,32.), input(incident_easting,32.), b.latitude, b.longitude)&amp;lt;=1.08  
   &amp;amp; (upcase(left(b.'247'n)) eqt 'Y' | upcase(left(put(datepart(a.eventtime),downame.)))=upcase(left(b.Type)) &amp;amp; b.open&amp;lt;=timepart(a.eventtime)&amp;lt;=b.close)) as d360_1080,
(select count(*) from Data_komplet  b where .z&amp;lt;intnx('dtyear',a.eventtime,0)&amp;lt;=b.createdtime&amp;lt;=a.eventtime
   &amp;amp; 1.08&amp;lt;geodist(input(incident_northing,32.), input(incident_easting,32.), b.latitude, b.longitude)&amp;lt;=1.8  
   &amp;amp; (upcase(left(b.'247'n)) eqt 'Y' | upcase(left(put(datepart(a.eventtime),downame.)))=upcase(left(b.Type)) &amp;amp; b.open&amp;lt;=timepart(a.eventtime)&amp;lt;=b.close)) as d1080_1800
from Final_database a;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The above code runs without error messages with test data I created, but I cannot be sure that your data has the same structure.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jun 2020 13:21:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/665348#M198933</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-06-26T13:21:16Z</dc:date>
    </item>
    <item>
      <title>Re: Generate new difficult variable that count observations based on location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/666286#M199327</link>
      <description>&lt;P&gt;Impressive&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm sorry for continuing to drop (stupid) questions and problems in your direction.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I run the full code from your last post:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table Data_komplet_Geo as
select a.*, 
(select count(*) from Data_komplet b where .z&amp;lt;intnx('dtyear',a.eventtime,0)&amp;lt;=b.createdtime&amp;lt;=a.eventtime 
   &amp;amp; 0&amp;lt;=geodist(input(incident_northing,32.), input(incident_easting,32.), b.latitude, b.longitude)&amp;lt;=0.360 
   &amp;amp; (upcase(left(b.'247'n)) eqt 'Y' | upcase(left(put(datepart(a.eventtime),downame.)))=upcase(left(b.Type)) &amp;amp; b.open&amp;lt;=timepart(a.eventtime)&amp;lt;=b.close)) as d0_360,
(select count(*) from Data_komplet  b where .z&amp;lt;intnx('dtyear',a.eventtime,0)&amp;lt;=b.createdtime&amp;lt;=a.eventtime
   &amp;amp; 0.360&amp;lt;geodist(input(incident_northing,32.), input(incident_easting,32.), b.latitude, b.longitude)&amp;lt;=1.08  
   &amp;amp; (upcase(left(b.'247'n)) eqt 'Y' | upcase(left(put(datepart(a.eventtime),downame.)))=upcase(left(b.Type)) &amp;amp; b.open&amp;lt;=timepart(a.eventtime)&amp;lt;=b.close)) as d360_1080,
(select count(*) from Data_komplet  b where .z&amp;lt;intnx('dtyear',a.eventtime,0)&amp;lt;=b.createdtime&amp;lt;=a.eventtime
   &amp;amp; 1.08&amp;lt;geodist(input(incident_northing,32.), input(incident_easting,32.), b.latitude, b.longitude)&amp;lt;=1.8  
   &amp;amp; (upcase(left(b.'247'n)) eqt 'Y' | upcase(left(put(datepart(a.eventtime),downame.)))=upcase(left(b.Type)) &amp;amp; b.open&amp;lt;=timepart(a.eventtime)&amp;lt;=b.close)) as d1080_1800
from Final_database a;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I get the new following error messages:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR: Expression using less than or equal (&amp;lt;=) has components that are of different data types.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: Expression using greater than or equal (&amp;gt;=) has components that are of different data types.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: Expression using less than or equal (&amp;lt;=) has components that are of different data types.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: Expression using greater than or equal (&amp;gt;=) has components that are of different data types.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: Expression using less than or equal (&amp;lt;=) has components that are of different data types.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;ERROR: Expression using greater than or equal (&amp;gt;=) has components that are of different data types.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is that because of the format or type of my different time variables used?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Eventtime: type = num, format = DATETIME19. (shown in my database as: "14MAY2018:13:15:10" from Final_database)&lt;/P&gt;
&lt;P&gt;Createdtime: type = num, format = DATETIME18. (shown in my database as: "11JAN13:09:52:00" from Data_komplet)&lt;/P&gt;
&lt;P&gt;Open: type = char, format = $CHAR8. (shown in my database as: "8:30:00" from Data_komplet)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Close: type = char, format = $CHAR8.&amp;nbsp;(shown in my database as: "16:00:00" from Data_komplet)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks once again!&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jul 2020 07:26:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/666286#M199327</guid>
      <dc:creator>Mikkel_madsen</dc:creator>
      <dc:date>2020-07-01T07:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: Generate new difficult variable that count observations based on location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/666317#M199337</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/324058"&gt;@Mikkel_madsen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;(...)&lt;/P&gt;
&lt;P&gt;Open: type = char, format = $CHAR8. (shown in my database as: "8:30:00" from Data_komplet)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Close: type = char, format = $CHAR8.&amp;nbsp;(shown in my database as: "16:00:00" from Data_komplet)&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;However, in &lt;A href="https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/664911#M198708" target="_blank" rel="noopener"&gt;an earlier post of this thread&lt;/A&gt; you wrote&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;3) The variables "Open" and "Close" are both numeric variables with the format TIME8. and the informat TIME11.&amp;nbsp;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;(and my suggested code relied on that statement).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The contradiction is obvious, but the error messages suggest that the two variables are in fact character variables which, of course, requires a conversion before a comparison with numeric values such as &lt;FONT face="courier new,courier"&gt;timepart(&lt;/FONT&gt;...&lt;FONT face="courier new,courier"&gt;)&lt;/FONT&gt;.&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#FF00FF"&gt;&lt;STRONG&gt;input(&lt;/STRONG&gt;&lt;/FONT&gt;b.open&lt;STRONG&gt;&lt;FONT color="#FF00FF"&gt;,time8.)&lt;/FONT&gt;&lt;/STRONG&gt;&amp;lt;=timepart(a.eventtime)&amp;lt;=&lt;STRONG&gt;&lt;FONT color="#FF00FF"&gt;input(&lt;/FONT&gt;&lt;/STRONG&gt;b.close&lt;STRONG&gt;&lt;FONT color="#FF00FF"&gt;,time8.)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can imagine how useful representative test data (in the form of a DATA step) would have been ...&lt;/P&gt;</description>
      <pubDate>Wed, 01 Jul 2020 10:01:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/666317#M199337</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-07-01T10:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: Generate new difficult variable that count observations based on location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/666582#M199465</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry! Several mistakes have been made and they are all mine. The open/ close variables was indeed numeric. However, I had trouble with the dataset, and I tried to export/ import it, which changed the variables to character (without me noticing). Sorry!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, whether I run it with or without the new modification (with the input function), I just get another error code:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;ERROR 79-322: Expecting a ).&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;Affected code: !! input(b.open,time8.)&amp;lt;=timepart(a.eventtime)&amp;lt;=input(b.close,time8.) as d0_360&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;The same errormessage is repeated three times (from each last line in all three new variables).&amp;nbsp;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do understand if you are feeling a bit tired, and it is totally okay if enough is enough! I'm also feeling a bit tired and thinking about other ways to do this. I would love to share a part of my original data but it is containing sensitive information that I'm not allowed to share.&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jul 2020 11:54:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generate-new-difficult-variable-that-count-observations-based-on/m-p/666582#M199465</guid>
      <dc:creator>Mikkel_madsen</dc:creator>
      <dc:date>2020-07-02T11:54:58Z</dc:date>
    </item>
  </channel>
</rss>

