<?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: create sorted date variable through macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/create-sorted-date-variable-through-macro/m-p/497334#M131783</link>
    <description>&lt;P&gt;Note that %SYSFUNC does not support the PUT function.&amp;nbsp; You would have to use PUTN instead.&lt;/P&gt;</description>
    <pubDate>Thu, 20 Sep 2018 12:29:33 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-09-20T12:29:33Z</dc:date>
    <item>
      <title>create sorted date variable through macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-sorted-date-variable-through-macro/m-p/497299#M131761</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;how can I create the date variable like No_of_cit200001,&lt;SPAN&gt;No_of_cit&lt;/SPAN&gt;200002...&lt;SPAN&gt;No_of_cit&lt;/SPAN&gt;200010,&lt;SPAN&gt;No_of_cit&lt;/SPAN&gt;200011 through macro variable .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use the following codes,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro  base_of_cit3;
   %local y;
   %do y=2000 %to 2010;

   %local m;
   &lt;STRONG&gt;%do m=1 %to 12;&lt;/STRONG&gt;
     PROC SQL;
        CREATE TABLE Step4.M_3cit&amp;amp;y.&amp;amp;m AS
         SELECT
           t_base.psn_name,
           COUNT(DISTINCT t_do.docdb_family_id) AS No_of_cit&amp;amp;y.&amp;amp;m
         FROM
           Pat_ori.Docdbfamiliescitations AS t_do
         JOIN Step3.M_2cit&amp;amp;y AS t_base ON t_do.cited_docdb_family_id=t_base.docdb_family_id_base
         JOIN Step1.appln_publn AS t_ap2 ON t_do.docdb_family_id=t_ap2.docdb_family_id
         WHERE month = &amp;amp;m
         AND t_ap2.publn_date &amp;lt;= intnx('year', t_base.earliest_publn_date,3) /*a 3-year moving window starting at the earliest publication date of a patent family */
        GROUP BY t_base.psn_name
        ORDER BY t_base.psn_name
;
QUIT;
   %end;     
   %end;

%mend base_of_cit3;   

%base_of_cit3;


/*Step3: merge and delete missing value at psn_name variable*/
DATA Step5.Number_of_cit_end;
MERGE Step4.M_3cit20: ;
BY psn_name;
IF psn_name='' THEN delete;
RUN;

/*Step4: replace ‘.’ with zero */
DATA RESULT.M_number_of_cit;
SET Step5.Number_of_cit_end;
ARRAY n{*} _numeric_; /* gets all numeric variables into array */
DO i=1 TO dim(n); /* Do for all elements */
IF n{i}=. then n{i}=0;
END;
DROP i;
RUN;

proc transpose data= RESULT.M_number_of_cit out=Step6.M_No_cit_t;
 by psn_name;
 var No_of_cit: ;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and get the result like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TIM图片20180920111856.png" style="width: 501px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/23409i01AA42394EF6286B/image-size/large?v=v2&amp;amp;px=999" role="button" title="TIM图片20180920111856.png" alt="TIM图片20180920111856.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to get&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;No_of_cit200001,
No_of_cit200002,
No_of_cit200003,
...
No_of_cit200010,
No_of_cit200011&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;for each psn_name.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please give me some suggestions?&lt;/P&gt;&lt;P&gt;thanks in advance&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 10:22:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-sorted-date-variable-through-macro/m-p/497299#M131761</guid>
      <dc:creator>France</dc:creator>
      <dc:date>2018-09-20T10:22:50Z</dc:date>
    </item>
    <item>
      <title>Re: create sorted date variable through macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-sorted-date-variable-through-macro/m-p/497300#M131762</link>
      <description>&lt;P&gt;Does not make sense.&amp;nbsp; Please follow the guidance, post test data in the form of a datastep and then show what you want out from that test data.&amp;nbsp; From what I can make out of your post you simply want to count a variable by a by group:&lt;/P&gt;
&lt;PRE&gt;proc means data=have;
  class psn_name;
  var ...;
  output out=want n=n;
run;&lt;/PRE&gt;
&lt;P&gt;No need for splitting data up, and macro etc.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 10:34:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-sorted-date-variable-through-macro/m-p/497300#M131762</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-20T10:34:10Z</dc:date>
    </item>
    <item>
      <title>Re: create sorted date variable through macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-sorted-date-variable-through-macro/m-p/497312#M131768</link>
      <description>&lt;P&gt;Dear RW9,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes I'd like to count a variable by the group. I have counted the number of patents&amp;nbsp;based on ballardw's&amp;nbsp;suggestion. And now I need to count to count the number of patent citations, and I want to merge these two tables. However, while the date of the number of patents is 200001, the date of the number of patent citations is 20001. So I cannot merge them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;could you please give me some suggestions?&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 11:22:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-sorted-date-variable-through-macro/m-p/497312#M131768</guid>
      <dc:creator>France</dc:creator>
      <dc:date>2018-09-20T11:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: create sorted date variable through macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-sorted-date-variable-through-macro/m-p/497320#M131773</link>
      <description>&lt;P&gt;Just convert one of them?&amp;nbsp; Its quite hard to code anything not knowing input test data or required output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 11:48:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-sorted-date-variable-through-macro/m-p/497320#M131773</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-20T11:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: create sorted date variable through macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-sorted-date-variable-through-macro/m-p/497328#M131778</link>
      <description>&lt;P&gt;Dear RW9,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please provide suggestions about how to create variables like No_of_cit2000&lt;STRONG&gt;01, &lt;/STRONG&gt;No_of_cit2000&lt;STRONG&gt;02&lt;/STRONG&gt;..., No_of_cit2000&lt;STRONG&gt;12.&lt;/STRONG&gt; I can only get the variable like&amp;nbsp;&amp;nbsp;No_of_cit20000&lt;STRONG&gt;1,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;No_of_cit20000&lt;STRONG&gt;2&lt;SPAN&gt;...,&lt;/SPAN&gt;&lt;/STRONG&gt;No_of_cit2000&lt;STRONG&gt;12&lt;/STRONG&gt; by using following codes.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro  base_of_cit3;
   %local y;
   %do y=2000 %to 2010;

   %local m;
   %do m=1 %to 12;
     PROC SQL;
        CREATE TABLE Step4.M_3cit&amp;amp;y.&amp;amp;m AS
         SELECT
           t_base.psn_name,
           COUNT(DISTINCT t_do.docdb_family_id) AS No_of_cit&amp;amp;y.&amp;amp;m
         FROM
           Pat_ori.Docdbfamiliescitations AS t_do
         JOIN Step3.M_2cit&amp;amp;y AS t_base ON t_do.cited_docdb_family_id=t_base.docdb_family_id_base
         JOIN Step1.appln_publn AS t_ap2 ON t_do.docdb_family_id=t_ap2.docdb_family_id
         WHERE month = &amp;amp;m
         AND t_ap2.publn_date &amp;lt;= intnx('year', t_base.earliest_publn_date,3) /*a 3-year moving window starting at the earliest publication date of a patent family */
        GROUP BY t_base.psn_name
        ORDER BY t_base.psn_name
;
QUIT;
   %end;     
   %end;

%mend base_of_cit3;   

%base_of_cit3;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Sep 2018 12:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-sorted-date-variable-through-macro/m-p/497328#M131778</guid>
      <dc:creator>France</dc:creator>
      <dc:date>2018-09-20T12:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: create sorted date variable through macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-sorted-date-variable-through-macro/m-p/497330#M131779</link>
      <description>&lt;P&gt;You would need to put m to z2, something like:&lt;/P&gt;
&lt;PRE&gt;step4.m_3cit&amp;amp;y.%sysfunc(put(&amp;amp;m.,z2.)) as&lt;/PRE&gt;
&lt;P&gt;However, I can only stress once more that splitting data up in lots of same chunks and then writing lots of macro to cope with that will give you a headache and break 90% of the time.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 12:20:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-sorted-date-variable-through-macro/m-p/497330#M131779</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-20T12:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: create sorted date variable through macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-sorted-date-variable-through-macro/m-p/497332#M131781</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/194466"&gt;@France&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Dear RW9,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please provide suggestions about how to create variables like No_of_cit2000&lt;STRONG&gt;01, &lt;/STRONG&gt;No_of_cit2000&lt;STRONG&gt;02&lt;/STRONG&gt;..., No_of_cit2000&lt;STRONG&gt;12.&lt;/STRONG&gt; I can only get the variable like&amp;nbsp;&amp;nbsp;No_of_cit20000&lt;STRONG&gt;1,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/STRONG&gt;No_of_cit20000&lt;STRONG&gt;2&lt;SPAN&gt;...,&lt;/SPAN&gt;&lt;/STRONG&gt;No_of_cit2000&lt;STRONG&gt;12&lt;/STRONG&gt; by using following codes.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Allow me to give the same advice as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is generally a bad idea to split up the data by month and year. It should all go into a single data set, and from there the analyses can be performed using the proper BY statement in whatever PROC you plan to use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now that you have been given the same advice twice, please don't ignore it.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 12:24:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-sorted-date-variable-through-macro/m-p/497332#M131781</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-09-20T12:24:36Z</dc:date>
    </item>
    <item>
      <title>Re: create sorted date variable through macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-sorted-date-variable-through-macro/m-p/497334#M131783</link>
      <description>&lt;P&gt;Note that %SYSFUNC does not support the PUT function.&amp;nbsp; You would have to use PUTN instead.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 12:29:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-sorted-date-variable-through-macro/m-p/497334#M131783</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-09-20T12:29:33Z</dc:date>
    </item>
    <item>
      <title>Re: create sorted date variable through macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-sorted-date-variable-through-macro/m-p/497342#M131790</link>
      <description>&lt;P&gt;Dear PaigeMiller,&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for both of your advice.&amp;nbsp;now I am trying to not split up the data by month, but I really do not know how&amp;nbsp;to get the result if I do not split the data by year.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;now I am using the following codes,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro  base_of_cit3;
   %local y;
   %do y=2000 %to 2010;

     PROC SQL;
        CREATE TABLE Step4.M_3cit&amp;amp;y AS
         SELECT
           t_base.psn_name,
           COUNT(DISTINCT(case WHEN month = 1 THEN t_do.docdb_family_id END) AS No_of_cit&amp;amp;y.01,
           COUNT(DISTINCT(case WHEN month = 2 THEN t_do.docdb_family_id END) AS No_of_cit&amp;amp;y.02,
           COUNT(DISTINCT(case WHEN month = 3 THEN t_do.docdb_family_id END) AS No_of_cit&amp;amp;y.03,
           COUNT(DISTINCT(case WHEN month = 4 THEN t_do.docdb_family_id END) AS No_of_cit&amp;amp;y.04,
           COUNT(DISTINCT(case WHEN month = 5 THEN t_do.docdb_family_id END) AS No_of_cit&amp;amp;y.05,
           COUNT(DISTINCT(case WHEN month = 6 THEN t_do.docdb_family_id END) AS No_of_cit&amp;amp;y.06,
           COUNT(DISTINCT(case WHEN month = 7 THEN t_do.docdb_family_id END) AS No_of_cit&amp;amp;y.07,
           COUNT(DISTINCT(case WHEN month = 8 THEN t_do.docdb_family_id END) AS No_of_cit&amp;amp;y.08,
           COUNT(DISTINCT(case WHEN month = 9 THEN t_do.docdb_family_id END) AS No_of_cit&amp;amp;y.09,
           COUNT(DISTINCT(case WHEN month = 10 THEN t_do.docdb_family_id END) AS No_of_cit&amp;amp;y.10,
           COUNT(DISTINCT(case WHEN month = 11 THEN t_do.docdb_family_id END) AS No_of_cit&amp;amp;y.11,
           COUNT(DISTINCT(case WHEN month = 12 THEN t_do.docdb_family_id END) AS No_of_cit&amp;amp;y.12
        FROM
         Pat_ori.Docdbfamiliescitations AS t_do
         JOIN Step3.M_2cit&amp;amp;y AS t_base ON t_do.cited_docdb_family_id=t_base.docdb_family_id_base
         JOIN Step1.appln_publn AS t_ap2 ON t_do.docdb_family_id=t_ap2.docdb_family_id
         WHERE t_ap2.publn_date &amp;lt;= intnx('year', t_base.earliest_publn_date,3) /*a 3-year moving window starting at the earliest publication date of a patent family */
        GROUP BY t_base.psn_name
        ORDER BY t_base.psn_name
;
QUIT;
   %end;     

%mend base_of_cit3;   

%base_of_cit3;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but the result shows that,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;NOTE: Line generated by the invoked macro "BASE_OF_CIT3".
105   WHEN month = 8 THEN t_do.docdb_family_id END) AS citation&amp;amp;y.08,        COUNT(DISTINCT(case WHEN
105! month = 9 THEN t_do.docdb_family_id END) AS citation&amp;amp;y.09,        COUNT(DISTINCT(case WHEN month
105! = 10 THEN t_do.docdb_family_id END) AS citation&amp;amp;y.10,
                                         --
                                         79
ERROR 79-322: Expecting a ).

NOTE: Line generated by the invoked macro "BASE_OF_CIT3".
106          COUNT(DISTINCT(case WHEN month = 11 THEN t_do.docdb_family_id END) AS citation&amp;amp;y.11,
                                                                                --
                                                                                79
106!    COUNT(DISTINCT(case WHEN month = 12 THEN t_do.docdb_family_id END) AS citation&amp;amp;y.12       FROM
106!          Pat_ori.Docdbfamiliescitations AS t_do         JOIN
NOTE: Line generated by the invoked macro "BASE_OF_CIT3".
106          COUNT(DISTINCT(case WHEN month = 11 THEN t_do.docdb_family_id END) AS citation&amp;amp;y.11,
106!    COUNT(DISTINCT(case WHEN month = 12 THEN t_do.docdb_family_id END) AS citation&amp;amp;y.12       FROM
                                                                           --
                                                                           79
106!          Pat_ori.Docdbfamiliescitations AS t_do         JOIN
ERROR 79-322: Expecting a ).

NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.02 seconds
      cpu time            0.03 seconds



&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Could you please give me some suggestions?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 12:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-sorted-date-variable-through-macro/m-p/497342#M131790</guid>
      <dc:creator>France</dc:creator>
      <dc:date>2018-09-20T12:53:56Z</dc:date>
    </item>
    <item>
      <title>Re: create sorted date variable through macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-sorted-date-variable-through-macro/m-p/497344#M131792</link>
      <description>&lt;P&gt;All of your COUNT calculations have two open parentheses but only one close parenthesis.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Sep 2018 12:58:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-sorted-date-variable-through-macro/m-p/497344#M131792</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-09-20T12:58:49Z</dc:date>
    </item>
    <item>
      <title>Re: create sorted date variable through macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/create-sorted-date-variable-through-macro/m-p/497767#M132059</link>
      <description>Dear Astounding,&lt;BR /&gt;&lt;BR /&gt;I really appreciate your suggestion.&lt;BR /&gt;have a nice day.</description>
      <pubDate>Fri, 21 Sep 2018 11:35:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/create-sorted-date-variable-through-macro/m-p/497767#M132059</guid>
      <dc:creator>France</dc:creator>
      <dc:date>2018-09-21T11:35:37Z</dc:date>
    </item>
  </channel>
</rss>

