<?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 Use numeric time stamp to split records in datasets based on month year combo in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-numeric-time-stamp-to-split-records-in-datasets-based-on/m-p/611641#M35267</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a number of very large SAS files which I need to output into different datasets so people can use them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I need to extract the year-month from the timestamp and then use a macro to split the dataset into N datasets based on what year-month combo it falls on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a macro I used before but I can't get it to work for my current dataset as I believe my timestamp variable is not in the correct unit. See sample code and data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data person;
   input name $ dept $ timestamp;
   datalines;
John Sales 1551485838322
Mary Acctng 1552386119514
Tony Sales 1556189821690
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro split;

	data _NULL_;
		length lst_data $200.;
		lst_data='';

		do i=0 to 11;
			dt=intnx('month','01Dec19'd,-i);
			lst_data=cat(strip(lst_data),' ','ready_',year(dt),put(month(dt),z2.));
		end;

		call symputx("lst_data",lst_data);
	run;

	data &amp;amp;lst_data.;
		set person;

		*Use the set function we stack all datasets on top of each other called clean_;
		%do i=1 %to %sysfunc(countw(&amp;amp;lst_data.));
			if period1=intnx('month','01Dec19'd,-&amp;amp;i.+1) then
				output %scan(&amp;amp;lst_data.,&amp;amp;i.,%str( )); /*need to amend as works in other program*/
		%end;
	run;

%mend;

%split;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 13 Dec 2019 16:35:29 GMT</pubDate>
    <dc:creator>Sean_OConnor</dc:creator>
    <dc:date>2019-12-13T16:35:29Z</dc:date>
    <item>
      <title>Use numeric time stamp to split records in datasets based on month year combo</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-numeric-time-stamp-to-split-records-in-datasets-based-on/m-p/611641#M35267</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a number of very large SAS files which I need to output into different datasets so people can use them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I need to extract the year-month from the timestamp and then use a macro to split the dataset into N datasets based on what year-month combo it falls on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a macro I used before but I can't get it to work for my current dataset as I believe my timestamp variable is not in the correct unit. See sample code and data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data person;
   input name $ dept $ timestamp;
   datalines;
John Sales 1551485838322
Mary Acctng 1552386119514
Tony Sales 1556189821690
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro split;

	data _NULL_;
		length lst_data $200.;
		lst_data='';

		do i=0 to 11;
			dt=intnx('month','01Dec19'd,-i);
			lst_data=cat(strip(lst_data),' ','ready_',year(dt),put(month(dt),z2.));
		end;

		call symputx("lst_data",lst_data);
	run;

	data &amp;amp;lst_data.;
		set person;

		*Use the set function we stack all datasets on top of each other called clean_;
		%do i=1 %to %sysfunc(countw(&amp;amp;lst_data.));
			if period1=intnx('month','01Dec19'd,-&amp;amp;i.+1) then
				output %scan(&amp;amp;lst_data.,&amp;amp;i.,%str( )); /*need to amend as works in other program*/
		%end;
	run;

%mend;

%split;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Dec 2019 16:35:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-numeric-time-stamp-to-split-records-in-datasets-based-on/m-p/611641#M35267</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2019-12-13T16:35:29Z</dc:date>
    </item>
    <item>
      <title>Re: Use numeric time stamp to split records in datasets based on month year combo</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-numeric-time-stamp-to-split-records-in-datasets-based-on/m-p/611692#M35269</link>
      <description>&lt;P&gt;Can you tell us what date (day month and year) and time of day (hours minutes seconds) your value of 1551485838322 is supposed to represent?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There may be issues with using timestamp as a numeric as the 16 digits you show are going to be up against the storage precision of a numeric value in SAS depending on your Operating system.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The value you show is NOT a valid SAS datetime value, which would be number of seconds since midnight (start of day) 01Jan1960.&lt;/P&gt;
&lt;P&gt;Either it is not valid or represents a datetime value. A twelve digit number in the range of 411502467600 gets into calendar year 15,000.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your timestamp has a significant fractional second component there may be something we can do but until we know the actual content we're guessing (unless someone else recognizes this particular value).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't see any attempt to actually use that timestamp value so it is hard to tell what you expect for output.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Dec 2019 18:50:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-numeric-time-stamp-to-split-records-in-datasets-based-on/m-p/611692#M35269</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-12-13T18:50:47Z</dc:date>
    </item>
    <item>
      <title>Re: Use numeric time stamp to split records in datasets based on month year combo</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-numeric-time-stamp-to-split-records-in-datasets-based-on/m-p/611753#M35270</link>
      <description>&lt;P&gt;Are those supposed to be Unix timestamp values (&lt;A href="http://timestamp.online/" target="_blank"&gt;http://timestamp.online/&lt;/A&gt;)? If so it looks like they are in milliseconds instead of seconds.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data person;
   input name $ dept $ timestamp;
   dt = timestamp/1000 + '31DEC1969:00:00'dt ;
   year = year(datepart(dt));
   month = month(datepart(dt));
   format dt datetime20.;
datalines;
John Sales 1551485838322
Mary Acctng 1552386119514
Tony Sales 1556189821690
;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    name     dept     timestamp                      dt    year    month

 1     John    Sales     1.5515E12      01MAR2019:00:17:18    2019      3
 2     Mary    Acctng    1.5524E12      11MAR2019:10:22:00    2019      3
 3     Tony    Sales     1.5562E12      24APR2019:10:57:02    2019      4&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Dec 2019 22:40:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Use-numeric-time-stamp-to-split-records-in-datasets-based-on/m-p/611753#M35270</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-13T22:40:02Z</dc:date>
    </item>
  </channel>
</rss>

