<?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: Scan a list of datetime16. in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823297#M35056</link>
    <description>&lt;P&gt;What about this rough outline of doing this without macros&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table vardtm as
    select distinct sample_dtm 
    from sampleID_database;
quit;
proc transpose data=vardtm out=vardtm1 prefix=time;
    var sample_dtm;
run;
data want;
     if _n_=1 then set vardtm1;
	set have;
	sampleid=.;
	if time1 le dtm le time2 then sampleid='1438';
	if dtm&amp;gt;time2 then sampleid='2348';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Naturally I can't test this because I don't have your data, but now the whole issue of writing macro code that works is gone, the problem caused by commas is gone, the data remains in SAS data sets instead of a long macro string that you have to pull apart. Please give this a shot and forget macros in this case.&lt;/P&gt;</description>
    <pubDate>Thu, 14 Jul 2022 13:39:53 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2022-07-14T13:39:53Z</dc:date>
    <item>
      <title>Scan a list of datetime16.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823286#M35050</link>
      <description>&lt;P&gt;Hi Everybody,&lt;BR /&gt;&lt;BR /&gt;I have a list of datetimes that I have made via SQL:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select distinct sample_dtm into :vardtm separated by ","
from sampleID_database
run;&lt;BR /&gt;%put &amp;amp;vardtm;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And the put statement gives me a list of three datetimes as required:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;02FEB20:15:20:00,12JUN20:15:26:50,24JUL20:16:20:12&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Now I want to do some operations with these dates. For a dataset, I want to (for example) say that if the date of an event is &lt;U&gt;before&lt;/U&gt; the second instance of &amp;amp;vardtm but &lt;U&gt;after&lt;/U&gt; the first instance of &amp;amp;vardtm, then do &lt;EM&gt;such-and-such.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I guessed I would have to use the SCAN function to get these different parts of my macro list. I thought that the following would identify the first datetime in my list, but it does not:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %scan(&amp;amp;vardtm,1,',');
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead, it gives the error:&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#993300"&gt;ERROR: A character operand was found in the %EVAL function or %IF&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#993300"&gt;condition where a numeric operand is required. The&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#993300"&gt;condition was: 02FEB20:15:20:00&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#993300"&gt;ERROR: Argument 2 to macro function %SCAN is not a number.&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;And what's more, if I do for example the following to actually do what I hoped to do, it obviously does not work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	set have;
	sampleid=.;
	if %scan(&amp;amp;vardtm,2,',') le dtm le %scan(&amp;amp;vardtm,2,',') then sampleid='1438';
	if dtm&amp;gt;%scan(&amp;amp;vardtm,2,',') then sampleid='2348';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Any help would be really appreciated!&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 13:07:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823286#M35050</guid>
      <dc:creator>linlin87</dc:creator>
      <dc:date>2022-07-14T13:07:34Z</dc:date>
    </item>
    <item>
      <title>Re: Scan a list of datetime16.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823290#M35051</link>
      <description>&lt;P&gt;The SAS code your macro code generates needs to be valid SAS syntax.&lt;/P&gt;
&lt;P&gt;You are currently generating this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if 02FEB20:15:20:00 le dtm ...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which is NOT valid.&lt;/P&gt;
&lt;P&gt;You can either add quotes and the letters dt so that the generated code is valid.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	if "%scan(&amp;amp;vardtm,2,',')"dt le dtm le "%scan(&amp;amp;vardtm,2,',')"dt then sampleid='1438';
	if dtm&amp;gt;"%scan(&amp;amp;vardtm,2,',')"dt then sampleid='2348';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or change the format used to create the macro variable so that the raw number of seconds is generated instead of the text that humans can look at.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select distinct sample_dtm format=best32.
  into :vardtm separated by ","
from sampleID_database&amp;nbsp;;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Jul 2022 13:17:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823290#M35051</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-14T13:17:47Z</dc:date>
    </item>
    <item>
      <title>Re: Scan a list of datetime16.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823293#M35052</link>
      <description>&lt;P&gt;Your %PUT statement fails because it sees the comma inside &amp;amp;vardtm and thinks this indicates the end of the first argument to %SCAN. In addition, if you are scanning for the text string&amp;nbsp;&lt;FONT face="courier new,courier"&gt;','&lt;/FONT&gt; this doesn't exist in your &amp;amp;vardtm and so %SCAN fails for both reasons.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The whole issue of putting commas between items to separate the items causes issues in macro processing. Nevertheless, the solution is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %scan(%quote(&amp;amp;vardtm),1,%str(,));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems to me that you make your life much easier by separating the date/time values with a space instead of a comma, but I'm skeptical that macro variables are needed here (more disucssion of that below)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then there are also the problems mentioned by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;that have to be fixed even if you get the %SCAN to work right.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All of which indicates to me that macro variables are not the best solution here, that these date/time values exist in a data set and instead of turning them into a macro string that has to be pulled apart, you should find a way (if possible) to use the values in a data set without macro variables at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 13:25:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823293#M35052</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-07-14T13:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: Scan a list of datetime16.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823294#M35053</link>
      <description>&lt;P&gt;Thanks Tom.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;The code is still not working. My 'want' has no observations:&lt;/P&gt;
&lt;PRE&gt;data want;
	set have;
	sampleid=.;
	if "%scan(&amp;amp;vardtm,1,',')"dt le dtm le "%scan(&amp;amp;vardtm,2,',')"dt then sampleid='1438';
	if dtm&amp;gt;"%scan(&amp;amp;vardtm,2,',')"dt then sampleid='2348';
run;&lt;/PRE&gt;
&lt;P&gt;I would expect that&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%put %scan(&amp;amp;vardtm,1,',');
%put %scan(&amp;amp;vardtm,2,',');&lt;/PRE&gt;
&lt;P&gt;would output the first two dates in the macro list, but instead it just says:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#993300"&gt;A character operand was found in the %EVAL function or %IF&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#993300"&gt;condition where a numeric operand is required. The&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#993300"&gt;condition was: &lt;SPAN&gt;02FEB20:15:20:00&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#993300"&gt;ERROR: Argument 2 to macro function %SCAN is not a number.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#993300"&gt;ERROR: A character operand was found in the %EVAL function or %IF&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#993300"&gt;condition where a numeric operand is required. The&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#993300"&gt;condition was: &lt;SPAN&gt;02FEB20:15:20:00&lt;/SPAN&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#993300"&gt;ERROR: Argument 2 to macro function %SCAN is not a number.&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 13:26:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823294#M35053</guid>
      <dc:creator>linlin87</dc:creator>
      <dc:date>2022-07-14T13:26:34Z</dc:date>
    </item>
    <item>
      <title>Re: Scan a list of datetime16.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823295#M35054</link>
      <description>&lt;P&gt;I think the solution is top replace the quotes around the commas with %str(,) and use %quote around &amp;amp;vardtm&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;such as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;"%scan(%quote(&amp;amp;vardtm),1,%str(,))"dt&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but as I said earlier, I think the whole thing could be programmed without macros and without macro variables, using data stored in SAS data sets (or external data bases). Doing this with macros just causes all sorts of issues (all of which can be overcome, but for beginners it isn't easy)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 13:34:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823295#M35054</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-07-14T13:34:02Z</dc:date>
    </item>
    <item>
      <title>Re: Scan a list of datetime16.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823296#M35055</link>
      <description>&lt;P&gt;Thanks Paige.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;It now works.&lt;BR /&gt;&lt;BR /&gt;But, out of interest, how would you do this in the alternative way you described?&lt;BR /&gt;&lt;BR /&gt;I guess it may be difficult to demonstrate without any concrete data.&lt;BR /&gt;&lt;BR /&gt;I basically have a dataset with a long list of temperature recordings and the datetime of the recording. These recordings come from sequential samples (at specific points in time, the sample is changed). I then have a separate dataset which has the datetimes at which the sample was changed. So I want to assign the temperature recordings to the correct sample, if you see what I mean?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 13:37:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823296#M35055</guid>
      <dc:creator>linlin87</dc:creator>
      <dc:date>2022-07-14T13:37:09Z</dc:date>
    </item>
    <item>
      <title>Re: Scan a list of datetime16.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823297#M35056</link>
      <description>&lt;P&gt;What about this rough outline of doing this without macros&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    create table vardtm as
    select distinct sample_dtm 
    from sampleID_database;
quit;
proc transpose data=vardtm out=vardtm1 prefix=time;
    var sample_dtm;
run;
data want;
     if _n_=1 then set vardtm1;
	set have;
	sampleid=.;
	if time1 le dtm le time2 then sampleid='1438';
	if dtm&amp;gt;time2 then sampleid='2348';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Naturally I can't test this because I don't have your data, but now the whole issue of writing macro code that works is gone, the problem caused by commas is gone, the data remains in SAS data sets instead of a long macro string that you have to pull apart. Please give this a shot and forget macros in this case.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 13:39:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823297#M35056</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-07-14T13:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: Scan a list of datetime16.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823301#M35057</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;PRE&gt;%put %scan(&amp;amp;vardtm,1,',');
%put %scan(&amp;amp;vardtm,2,',');&lt;/PRE&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Again look that what code you have asked the macro processor to generate.&amp;nbsp; In this case the evaluation of &amp;amp;VARDTM is generating code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %scan(01JAN22:01:02:03,02FEB21:00:00:00,1,',');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which has way too many commas for the %SCAN() function.&lt;/P&gt;
&lt;P&gt;Also why are you asking %SCAN() to use both comma and single quote as the delimiter characters?&lt;/P&gt;
&lt;P&gt;You could use the second mistake to cancel the first by adding double quote characters to the list of delimiters.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %scan("&amp;amp;vardtm",1,",");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you are generating valid (if strange) code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %scan("01JAN22:01:02:03,02FEB21:00:00:00",1,",");&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Why not just use a different delimiter. Something that is not used by the macro language or the output of the datetime format.&lt;/P&gt;
&lt;P&gt;So if you build the string with | as the delimiter then your code could be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %scan(&amp;amp;vardtm,1,|);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which will evaluate to this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %scan(01JAN22:01:02:03|02FEB21:00:00:00,1,|);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 13:41:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823301#M35057</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-14T13:41:56Z</dc:date>
    </item>
    <item>
      <title>Re: Scan a list of datetime16.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823311#M35059</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/426087"&gt;@linlin87&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks Paige.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;It now works.&lt;BR /&gt;&lt;BR /&gt;But, out of interest, how would you do this in the alternative way you described?&lt;BR /&gt;&lt;BR /&gt;I guess it may be difficult to demonstrate without any concrete data.&lt;BR /&gt;&lt;BR /&gt;I basically have a dataset with a long list of temperature recordings and the datetime of the recording. These recordings come from sequential samples (at specific points in time, the sample is changed). I then have a separate dataset which has the datetimes at which the sample was changed. So I want to assign the temperature recordings to the correct sample, if you see what I mean?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Just use SQL to join.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you have a list of dates with SAMPLEID attached and you want to combine it with another list of dates you should be able to just JOIN the two tables by the criteria.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if SAMPLES is the dataset with the SAMPLEID values and OTHER is the table with the dates you want to match use something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select a.*
     , b.sampleid
from other a
  left join samples b
  on a.date between b.date-7 and b.date+7 
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Fix the join criteria to match your situation.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 13:49:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823311#M35059</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-14T13:49:35Z</dc:date>
    </item>
    <item>
      <title>Re: Scan a list of datetime16.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823312#M35060</link>
      <description>&lt;P&gt;Thank you Paige and Tom for the alternative methods of solving this.&lt;BR /&gt;&lt;BR /&gt;One question: I have to run this process numerous times for different files. In some files there are 3 samples (and therefore dates) and in other files there are more (up to 7). This changes as more data comes in for the samples, we may get more than 7 so I want to be flexible with this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't want to have to keep checking this and hard coding:&lt;/P&gt;
&lt;PRE&gt;time1 &amp;lt; dtm &amp;lt; time2
time2 &amp;lt; dtm &amp;lt; time3
time3 &amp;lt; dtm &amp;lt; time4
...&lt;/PRE&gt;
&lt;P&gt;Which application would you recommend?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 13:55:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823312#M35060</guid>
      <dc:creator>linlin87</dc:creator>
      <dc:date>2022-07-14T13:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: Scan a list of datetime16.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823316#M35061</link>
      <description>&lt;P&gt;From your original code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	if %scan(&amp;amp;vardtm,2,',') le dtm le %scan(&amp;amp;vardtm,2,',') then sampleid='1438';
	if dtm&amp;gt;%scan(&amp;amp;vardtm,2,',') then sampleid='2348';
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;where are these sampleID values stored?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 14:10:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823316#M35061</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-07-14T14:10:06Z</dc:date>
    </item>
    <item>
      <title>Re: Scan a list of datetime16.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823326#M35063</link>
      <description>&lt;P&gt;If you share some example data (mock something up that simulates your issues in as small a sample as possible) then you can get a better answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It looks perhaps like you are trying to assign the most recent value based on dates.&lt;/P&gt;
&lt;P&gt;So if you have one dataset with sampleid and sampledate and you want to combine with another dataset with result dates you might get what you want by INTERLEAVING the two datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So it might looks something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set samples(in=in1) results(in=in2);
  by id date ;
  retain xx ;
  if first.id then call missing(xx);
  if in1 then xx=sampleid;
  if in2;
  sampleid=xx;
  drop xx;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 14:24:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823326#M35063</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-07-14T14:24:27Z</dc:date>
    </item>
    <item>
      <title>Re: Scan a list of datetime16.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823331#M35064</link>
      <description>&lt;P&gt;Using regular datetime variables, I &lt;STRIKE&gt;can&lt;/STRIKE&gt; &lt;EM&gt;&lt;STRONG&gt;can't&lt;/STRONG&gt;&lt;/EM&gt; get SQL to produce this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;02FEB20:15:20:00,12JUN20:15:26:50,24JUL20:16:20:12&lt;/PRE&gt;
&lt;P&gt;from this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select distinct sample_dtm into :vardtm separated by ","
  from sampleID_database;
quit;
%put &amp;amp;vardtm;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so I assume that sample_dtm is a character variable.&amp;nbsp; In that case, you can use the CATS function as below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select distinct cats("'",sample_dtm,"'dt") into :vardtm separated by ","
  from sampleID_database;
quit;
%let ndates=&amp;amp;sqlobs;
%put &amp;amp;=vardtm;
%put &amp;amp;=ndates;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which, with my sample data produces&lt;/P&gt;
&lt;PRE&gt;359  %put &amp;amp;=vardtm;
VARDTM='01JAN2018:13:00:00'dt,'02JAN2018:14:00:00'dt,'03JAN2018:15:00:00'dt,'04JAN2018:16:00:00'dt
,'05JAN2018:17:00:00'dt
360  %put &amp;amp;=ndates;
NDATES=5

&lt;/PRE&gt;
&lt;P&gt;in the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now you have a comma-separated list of date time literals in your macrovar VARDTM that you can loop through, which should not require any further transformation to be useful in subsequent code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And you also know the number of literals from the NDATES macrovar.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And the other advantage of this is that the macro values are human readable.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 15:02:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823331#M35064</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-07-14T15:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: Scan a list of datetime16.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823346#M35068</link>
      <description>&lt;P&gt;Hi Paige,&lt;/P&gt;
&lt;P&gt;If I now want to assign&lt;/P&gt;
&lt;PRE&gt;%scan(%quote(&amp;amp;vardtm),1,%str(,))&lt;/PRE&gt;
&lt;P&gt;as a date within a datastep, how do I refer to it?&lt;/P&gt;
&lt;PRE&gt;data want;
set have;
format sample_dtm datetime16.;
sample_dtm = "%scan(%quote(&amp;amp;vardtm),2,%str(,))";
run;&lt;/PRE&gt;
&lt;P&gt;Should I use input?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 15:52:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823346#M35068</guid>
      <dc:creator>linlin87</dc:creator>
      <dc:date>2022-07-14T15:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: Scan a list of datetime16.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823351#M35069</link>
      <description>&lt;P&gt;How do you know which time goes with which sample ID?&lt;/P&gt;
&lt;P&gt;How is that time data set structured? You show the macro variable just getting the time component so not sure how the rest of your program is structured.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are two options I would recommend:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Create a format that groups each time into sampleIDs and maps the times to the samples using an INPUT function&lt;/LI&gt;
&lt;LI&gt;Restructure your time to SampleID data set to support a join.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would not use macro's here as they're cumbersome, the logic is difficult to verify, test and maintain.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you can make some fake data of each data set and show how the data is structured we can show how the code should be designed.&amp;nbsp;&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/426087"&gt;@linlin87&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you Paige and Tom for the alternative methods of solving this.&lt;BR /&gt;&lt;BR /&gt;One question: I have to run this process numerous times for different files. In some files there are 3 samples (and therefore dates) and in other files there are more (up to 7). This changes as more data comes in for the samples, we may get more than 7 so I want to be flexible with this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't want to have to keep checking this and hard coding:&lt;/P&gt;
&lt;PRE&gt;time1 &amp;lt; dtm &amp;lt; time2
time2 &amp;lt; dtm &amp;lt; time3
time3 &amp;lt; dtm &amp;lt; time4
...&lt;/PRE&gt;
&lt;P&gt;Which application would you recommend?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 16:03:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823351#M35069</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-07-14T16:03:10Z</dc:date>
    </item>
    <item>
      <title>Re: Scan a list of datetime16.</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823366#M35072</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/426087"&gt;@linlin87&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi Paige,&lt;/P&gt;
&lt;P&gt;If I now want to assign&lt;/P&gt;
&lt;PRE&gt;%scan(%quote(&amp;amp;vardtm),1,%str(,))&lt;/PRE&gt;
&lt;P&gt;as a date within a datastep, how do I refer to it?&lt;/P&gt;
&lt;PRE&gt;data want;
set have;
format sample_dtm datetime16.;
sample_dtm = "%scan(%quote(&amp;amp;vardtm),2,%str(,))";
run;&lt;/PRE&gt;
&lt;P&gt;Should I use input?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I gave an example, you extract the date/time values from the database into a SAS data set, transpose the data set, and then use it. The variables are now named TIME1 TIME2 ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No macros or macro variables needed.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 17:07:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Scan-a-list-of-datetime16/m-p/823366#M35072</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-07-14T17:07:40Z</dc:date>
    </item>
  </channel>
</rss>

