<?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: Transfer macro variable to a query after rsubmit statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Transfer-macro-variable-to-a-query-after-rsubmit-statement/m-p/826411#M326423</link>
    <description>&lt;P&gt;Because you specified YYMMDDN8. as the format for the %sysfunc function, you are uploading macrovar one_day_ago_fmt as the character value &lt;EM&gt;&lt;STRONG&gt;20220729&lt;/STRONG&gt;&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The value is treated as a numeric in the a.datadate=20220729 filter in your SQL.&amp;nbsp; Which actually means you are looking for a date that is 20220729 days after Jan 1, 1960&amp;nbsp; (i.e. over 55,000 years from now).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to filter for a.datadate='29JUL2022'd&amp;nbsp; (or better yet for macro usage&amp;nbsp; &amp;nbsp;"29JUL2022"d).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Change the output format of the SYSFUNC to &lt;EM&gt;&lt;STRONG&gt;DATE9.&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;Change a.datadate=&amp;amp;one_day_ago_fmt&amp;nbsp; to&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;a.datadate="&amp;amp;one_day_ago_fmt"d&lt;/STRONG&gt;&lt;/EM&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Editted addition:&amp;nbsp; Also you can make your program faster by converting your two steps to one step - i.e. do both the filtering and sorting in the same step.&amp;nbsp; In your case, I would recommend:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=comp.secd out=firms_us_current  ;
  where datadate="&amp;amp;one_day_ago_fmt"d;
  by conm;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This writes your subset of SECD to disk only once.&amp;nbsp; It's efficient because the WHERE filter is implemented by the data engine, so PROC SORT never sees the unwanted observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, why did you use NODUPKEYS in your proc sort?&amp;nbsp; How would PROC SORT know which company record for a given CONM you actually want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 01 Aug 2022 11:48:37 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2022-08-01T11:48:37Z</dc:date>
    <item>
      <title>Transfer macro variable to a query after rsubmit statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transfer-macro-variable-to-a-query-after-rsubmit-statement/m-p/826409#M326421</link>
      <description>&lt;P&gt;Dear&amp;nbsp; SAS users,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to know how to resolve the issue below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let psw=xxxxxxxx;
%let username=xxxxxx;

/* 	Push the macro variables to the remote server (without the next line the WRDS server 
	would not 'understand' &amp;amp;vars etc); */
%let wrds = wrds.wharton.upenn.edu 4016;options comamid = TCP remote=WRDS;
signon  noscript user='xxxx'  password="&amp;amp;psw";


 %let one_day_ago_fmt = 
  %sysfunc(
   intnx(
   day,             /* unit of time interval */
   %sysfunc(today()), /* function to get current date */
   -3,                /* number of intervals, negative goes to the past */
   same               /* alignment of interval date. "Same" is for same day of month */
   ), YYMMDDN8. /*date9.*/  /* Tell %SYSFUNC how to format the result */
  );


%syslput one_day_ago_fmt=&amp;amp;one_day_ago_fmt ;
 %put &amp;amp;=one_day_ago_fmt;
 

rsubmit;
libname comp '/wrds/comp/sasdata/d_na';




/*Get returns after conditional exercise date*/
PROC SQL;
       create table firms_us_current as
       select *
       from  comp.secd a
  	  where a.DATADATE=&amp;amp;one_day_ago_fmt;/*'29Jul2022'd*/
quit;

 %put &amp;amp;=six_mo_ago_fmt;

proc sort data=firms_us_current out=firms_us_current nodupkeys;
     by  conm ;
run;

proc download data=firms_us_current out=firms_us_current ;run;
endrsubmit;
signoff;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This code is running to get remotely data for stock prices from compustat but actuallly the date is not captured by the macro variable and the data returns no observations.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please let me know how to address this issue.&lt;/P&gt;
&lt;P&gt;Many thanks in advance&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;George&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2022 11:17:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transfer-macro-variable-to-a-query-after-rsubmit-statement/m-p/826409#M326421</guid>
      <dc:creator>georgel</dc:creator>
      <dc:date>2022-08-01T11:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: Transfer macro variable to a query after rsubmit statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transfer-macro-variable-to-a-query-after-rsubmit-statement/m-p/826410#M326422</link>
      <description>&lt;P&gt;Show us the ENTIRE log for this code (every single line, every single character in the log for this code; do not select parts of the log to show us)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Copy the log as text and paste it into the window that appears when you click on the &amp;lt;/&amp;gt; icon.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Insert Log Icon in SAS Communities.png" style="width: 859px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66171iFEC370B1DBF07B28/image-size/large?v=v2&amp;amp;px=999" role="button" title="Insert Log Icon in SAS Communities.png" alt="Insert Log Icon in SAS Communities.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the future, when code isn't working, show us the log as explained here.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2022 11:24:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transfer-macro-variable-to-a-query-after-rsubmit-statement/m-p/826410#M326422</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-08-01T11:24:29Z</dc:date>
    </item>
    <item>
      <title>Re: Transfer macro variable to a query after rsubmit statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transfer-macro-variable-to-a-query-after-rsubmit-statement/m-p/826411#M326423</link>
      <description>&lt;P&gt;Because you specified YYMMDDN8. as the format for the %sysfunc function, you are uploading macrovar one_day_ago_fmt as the character value &lt;EM&gt;&lt;STRONG&gt;20220729&lt;/STRONG&gt;&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The value is treated as a numeric in the a.datadate=20220729 filter in your SQL.&amp;nbsp; Which actually means you are looking for a date that is 20220729 days after Jan 1, 1960&amp;nbsp; (i.e. over 55,000 years from now).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to filter for a.datadate='29JUL2022'd&amp;nbsp; (or better yet for macro usage&amp;nbsp; &amp;nbsp;"29JUL2022"d).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Change the output format of the SYSFUNC to &lt;EM&gt;&lt;STRONG&gt;DATE9.&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;Change a.datadate=&amp;amp;one_day_ago_fmt&amp;nbsp; to&lt;BR /&gt;&amp;nbsp; &amp;nbsp;&lt;EM&gt;&lt;STRONG&gt;a.datadate="&amp;amp;one_day_ago_fmt"d&lt;/STRONG&gt;&lt;/EM&gt;&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Editted addition:&amp;nbsp; Also you can make your program faster by converting your two steps to one step - i.e. do both the filtering and sorting in the same step.&amp;nbsp; In your case, I would recommend:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=comp.secd out=firms_us_current  ;
  where datadate="&amp;amp;one_day_ago_fmt"d;
  by conm;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This writes your subset of SECD to disk only once.&amp;nbsp; It's efficient because the WHERE filter is implemented by the data engine, so PROC SORT never sees the unwanted observations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, why did you use NODUPKEYS in your proc sort?&amp;nbsp; How would PROC SORT know which company record for a given CONM you actually want?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2022 11:48:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transfer-macro-variable-to-a-query-after-rsubmit-statement/m-p/826411#M326423</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-08-01T11:48:37Z</dc:date>
    </item>
    <item>
      <title>Re: Transfer macro variable to a query after rsubmit statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transfer-macro-variable-to-a-query-after-rsubmit-statement/m-p/826413#M326425</link>
      <description>&lt;P&gt;Dear Keintz&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a million for your illustrative and simplified approach at the end!&lt;/P&gt;
&lt;P&gt;Great!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;George&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2022 12:01:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transfer-macro-variable-to-a-query-after-rsubmit-statement/m-p/826413#M326425</guid>
      <dc:creator>georgel</dc:creator>
      <dc:date>2022-08-01T12:01:45Z</dc:date>
    </item>
    <item>
      <title>Re: Transfer macro variable to a query after rsubmit statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transfer-macro-variable-to-a-query-after-rsubmit-statement/m-p/826414#M326426</link>
      <description>&lt;P&gt;Dear Miller,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many thanks. Next time i will try your indicative format&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best ,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;George&lt;/P&gt;</description>
      <pubDate>Mon, 01 Aug 2022 12:03:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transfer-macro-variable-to-a-query-after-rsubmit-statement/m-p/826414#M326426</guid>
      <dc:creator>georgel</dc:creator>
      <dc:date>2022-08-01T12:03:00Z</dc:date>
    </item>
  </channel>
</rss>

