<?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: Help with Date Variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-with-Date-Variables/m-p/462168#M284870</link>
    <description>&lt;P&gt;Create macro variables is the easiest way.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use INTNX to get the variables and then increment as needed.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an example to create the macro variable for the start, and then you would use it as as follows. You may have issues with your URL and the &amp;amp; signs in it, which will be assumed to be macro variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let month=%sysfunc(intnx(month, %sysfunc(today()), -1, b), yymmddd10.);
%put &amp;amp;month;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;url = ".......&amp;amp;begindate=&amp;amp;month.";&lt;/CODE&gt;&lt;/PRE&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/210017"&gt;@CTurley&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I have the following code that requests data from an API.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note in the url, I have to hardcode the begin and end date. I want to use variables here. I want the begin date to be the first day of the current quarter and the end date to be todays date - 1. How do I do this in the code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Version says SAS EG 7.13 HF5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;filename criteo '/opt/sas/data/sasuser/sn161735/criteo.json';&lt;/P&gt;
&lt;P&gt;proc http&lt;BR /&gt;url="&lt;A href="https://publishers.criteo.com/api/2.0/stats.json?apitoken=XXX&amp;amp;" target="_blank"&gt;https://publishers.criteo.com/api/2.0/stats.json?apitoken=XXX&amp;amp;&lt;/A&gt;&lt;STRONG&gt;begindate=2018-04-01&lt;/STRONG&gt;&amp;amp;&lt;STRONG&gt;enddate=2018-04-25&lt;/STRONG&gt;&amp;amp;metrics=Date;TotalImpression;CPM;Revenue;WinRate"&lt;BR /&gt;method="GET" out=criteo&lt;BR /&gt;webusername="cturley@scrippsnetworks.com"&lt;BR /&gt;webpassword="kn0xv1lle"&lt;BR /&gt;AUTH_BASIC;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;libname criteo json fileref=criteo;&lt;/P&gt;
&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE WORK.CRITEO_DATA AS&lt;BR /&gt;SELECT t1.date,&lt;BR /&gt;t1.totalImpression FORMAT=COMMA9. AS totalImpression,&lt;BR /&gt;t2.value FORMAT=DOLLAR9.2 AS Revenue,&lt;BR /&gt;t3.value FORMAT=DOLLAR6.2 AS CPM&lt;BR /&gt;FROM CRITEO.ROOT t1, CRITEO.REVENUE t2, CRITEO.CPM t3&lt;BR /&gt;WHERE (t1.ordinal_root = t2.ordinal_root AND t1.ordinal_root = t3.ordinal_root);&lt;BR /&gt;QUIT;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 14 May 2018 19:15:14 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-05-14T19:15:14Z</dc:date>
    <item>
      <title>Help with Date Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-Date-Variables/m-p/462162#M284869</link>
      <description>&lt;P&gt;I have the following code that requests data from an API.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note in the url, I have to hardcode the begin and end date. I want to use variables here. I want the begin date to be the first day of the current quarter and the end date to be todays date - 1. How do I do this in the code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Version says SAS EG 7.13 HF5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;filename criteo '/opt/sas/data/sasuser/sn161735/criteo.json';&lt;/P&gt;&lt;P&gt;proc http&lt;BR /&gt;url="&lt;A href="https://publishers.criteo.com/api/2.0/stats.json?apitoken=XXX&amp;amp;" target="_blank"&gt;https://publishers.criteo.com/api/2.0/stats.json?apitoken=XXX&amp;amp;&lt;/A&gt;&lt;STRONG&gt;begindate=2018-04-01&lt;/STRONG&gt;&amp;amp;&lt;STRONG&gt;enddate=2018-04-25&lt;/STRONG&gt;&amp;amp;metrics=Date;TotalImpression;CPM;Revenue;WinRate"&lt;BR /&gt;method="GET" out=criteo&lt;BR /&gt;webusername="cturley@scrippsnetworks.com"&lt;BR /&gt;webpassword="kn0xv1lle"&lt;BR /&gt;AUTH_BASIC;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;libname criteo json fileref=criteo;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE WORK.CRITEO_DATA AS&lt;BR /&gt;SELECT t1.date,&lt;BR /&gt;t1.totalImpression FORMAT=COMMA9. AS totalImpression,&lt;BR /&gt;t2.value FORMAT=DOLLAR9.2 AS Revenue,&lt;BR /&gt;t3.value FORMAT=DOLLAR6.2 AS CPM&lt;BR /&gt;FROM CRITEO.ROOT t1, CRITEO.REVENUE t2, CRITEO.CPM t3&lt;BR /&gt;WHERE (t1.ordinal_root = t2.ordinal_root AND t1.ordinal_root = t3.ordinal_root);&lt;BR /&gt;QUIT;&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 19:00:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-Date-Variables/m-p/462162#M284869</guid>
      <dc:creator>CTurley</dc:creator>
      <dc:date>2018-05-14T19:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Date Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-Date-Variables/m-p/462168#M284870</link>
      <description>&lt;P&gt;Create macro variables is the easiest way.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use INTNX to get the variables and then increment as needed.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's an example to create the macro variable for the start, and then you would use it as as follows. You may have issues with your URL and the &amp;amp; signs in it, which will be assumed to be macro variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let month=%sysfunc(intnx(month, %sysfunc(today()), -1, b), yymmddd10.);
%put &amp;amp;month;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;url = ".......&amp;amp;begindate=&amp;amp;month.";&lt;/CODE&gt;&lt;/PRE&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/210017"&gt;@CTurley&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I have the following code that requests data from an API.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note in the url, I have to hardcode the begin and end date. I want to use variables here. I want the begin date to be the first day of the current quarter and the end date to be todays date - 1. How do I do this in the code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Version says SAS EG 7.13 HF5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;filename criteo '/opt/sas/data/sasuser/sn161735/criteo.json';&lt;/P&gt;
&lt;P&gt;proc http&lt;BR /&gt;url="&lt;A href="https://publishers.criteo.com/api/2.0/stats.json?apitoken=XXX&amp;amp;" target="_blank"&gt;https://publishers.criteo.com/api/2.0/stats.json?apitoken=XXX&amp;amp;&lt;/A&gt;&lt;STRONG&gt;begindate=2018-04-01&lt;/STRONG&gt;&amp;amp;&lt;STRONG&gt;enddate=2018-04-25&lt;/STRONG&gt;&amp;amp;metrics=Date;TotalImpression;CPM;Revenue;WinRate"&lt;BR /&gt;method="GET" out=criteo&lt;BR /&gt;webusername="cturley@scrippsnetworks.com"&lt;BR /&gt;webpassword="kn0xv1lle"&lt;BR /&gt;AUTH_BASIC;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;libname criteo json fileref=criteo;&lt;/P&gt;
&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE WORK.CRITEO_DATA AS&lt;BR /&gt;SELECT t1.date,&lt;BR /&gt;t1.totalImpression FORMAT=COMMA9. AS totalImpression,&lt;BR /&gt;t2.value FORMAT=DOLLAR9.2 AS Revenue,&lt;BR /&gt;t3.value FORMAT=DOLLAR6.2 AS CPM&lt;BR /&gt;FROM CRITEO.ROOT t1, CRITEO.REVENUE t2, CRITEO.CPM t3&lt;BR /&gt;WHERE (t1.ordinal_root = t2.ordinal_root AND t1.ordinal_root = t3.ordinal_root);&lt;BR /&gt;QUIT;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 19:15:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-Date-Variables/m-p/462168#M284870</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-05-14T19:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Date Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-Date-Variables/m-p/462196#M284871</link>
      <description>&lt;P&gt;It is probably easier to generate into a macro variable using a data step and avoid having to work with dates in macro code.&lt;/P&gt;
&lt;P&gt;You can use single quotes around the URL in the macro variable to prevent SAS from trying to convert find macro variables named BEGINDATE, ENDDATE or METRICS.&lt;/P&gt;
&lt;P&gt;Something like this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  enddate=today();
  begindate=intnx('qtr',enddate,0,'b');
  token='XXX';
  length url $300 ;
  url=quote(cats('https://publishers.criteo.com/api/2.0/stats.json?apitoken=',token
   ,'&amp;amp;begindate=',put(begindate,yymmddd10.)
   ,'&amp;amp;enddate=',put(enddate,yymmddd10.)
   ,'&amp;amp;metrics=Date;TotalImpression;CPM;Revenue;WinRate'
   ),"'");
  call symputx('url',url);
  call symputx('webusername',quote("YYYYYY"));
  call symputx('webpassword',quote("ZZZZZZ"));
run;

proc http url=&amp;amp;url method="GET" out=criteo
  webusername=&amp;amp;webusername
  webpassword=&amp;amp;webpassword
  AUTH_BASIC
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 May 2018 20:40:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-Date-Variables/m-p/462196#M284871</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-05-14T20:40:03Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Date Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-Date-Variables/m-p/462199#M284872</link>
      <description>&lt;P&gt;Even with hard-coded values, this program has issues.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have double-quotes around the URL.&amp;nbsp; So how do you prevent &amp;amp;METRIC from being interpreted as a reference to the macro variable METRIC?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What if you were to run the program on the first day of the quarter?&amp;nbsp; Then the begin date would come after the end date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These are issues you can code around, beginning with the tools that &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;mentioned.&amp;nbsp; The formulas might need to be adjusted, but that can be done:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let begin = %sysfunc(intnx(quarter, "&amp;amp;sysdate9"d, 0), yymmddd10.);&lt;/P&gt;
&lt;P&gt;%let end = %sysfunc(putn("&amp;amp;sysdate9"d - 1, yymmddd10.));&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But what about the other questions that I raised?&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 20:46:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-Date-Variables/m-p/462199#M284872</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-05-14T20:46:35Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Date Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-Date-Variables/m-p/462385#M284873</link>
      <description>&lt;P&gt;This has me close. When I run this code, I get the data for the first day of the quarter only. (4-1-2018). I thought it was due to having the last day being today. My API's do not like that. I changed the endate parameter by adding -1. I have the code blow. I also tried to make the url length higher but that had no effect either. Any idea why I only get one days data?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;filename criteo '/opt/sas/data/sasuser/sn161735/criteo.json';&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt;enddate=today()-1;&lt;BR /&gt;begindate=intnx('qtr',enddate,0,'b');&lt;BR /&gt;token='xxx';&lt;BR /&gt;length url $1300 ;&lt;BR /&gt;url=quote(cats('&lt;A href="https://publishers.criteo.com/api/2.0/stats.json?apitoken=',token" target="_blank"&gt;https://publishers.criteo.com/api/2.0/stats.json?apitoken=',token&lt;/A&gt;&lt;BR /&gt;,'&amp;amp;begindate=',put(begindate,yymmddd10.)&lt;BR /&gt;,'&amp;amp;enddate=',put(enddate,yymmddd10.)&lt;BR /&gt;,'&amp;amp;metrics=Date;TotalImpression;CPM;Revenue;WinRate'&lt;BR /&gt;),"'");&lt;BR /&gt;call symputx('url',url);&lt;BR /&gt;call symputx('webusername',quote("cturley@sxx"));&lt;BR /&gt;call symputx('webpassword',quote("xxx"));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc http url=&amp;amp;url method="GET" out=criteo&lt;BR /&gt;webusername=&amp;amp;webusername&lt;BR /&gt;webpassword=&amp;amp;webpassword&lt;BR /&gt;AUTH_BASIC&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE CRITEO_DATA AS&lt;BR /&gt;SELECT t1.date,&lt;BR /&gt;t1.totalImpression FORMAT=COMMA9. AS totalImpression,&lt;BR /&gt;t2.value FORMAT=DOLLAR9.2 AS Revenue,&lt;BR /&gt;t3.value FORMAT=DOLLAR6.2 AS CPM&lt;BR /&gt;FROM CRITEO.ROOT t1, CRITEO.REVENUE t2, CRITEO.CPM t3&lt;BR /&gt;WHERE (t1.ordinal_root = t2.ordinal_root AND t1.ordinal_root = t3.ordinal_root);&lt;BR /&gt;QUIT;&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2018 15:24:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-Date-Variables/m-p/462385#M284873</guid>
      <dc:creator>CTurley</dc:creator>
      <dc:date>2018-05-15T15:24:16Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Date Variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-Date-Variables/m-p/462404#M284874</link>
      <description>&lt;P&gt;You could add a PUT statement to the data _null_ to dump the URL that you generated to make sure it is formatted as expected.&lt;/P&gt;
&lt;P&gt;You could also look at the resulting JSON file and make sure that the return is what you expected.&lt;/P&gt;
&lt;P&gt;How are you converting the JSON output into SAS dataset?&amp;nbsp; Perhaps that step is not working now?&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2018 15:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-Date-Variables/m-p/462404#M284874</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-05-15T15:58:47Z</dc:date>
    </item>
  </channel>
</rss>

