<?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: ERROR in extracting date columns with certain format from a library and display only year. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/ERROR-in-extracting-date-columns-with-certain-format-from-a/m-p/320451#M70592</link>
    <description>&lt;P&gt;I agree. &amp;nbsp;I have mentioned this many times, however the user appears to be&amp;nbsp;re-writing the enitre Base SAS library in macro only, and is unwilling to post test data or format code.&lt;/P&gt;</description>
    <pubDate>Wed, 21 Dec 2016 09:35:41 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-12-21T09:35:41Z</dc:date>
    <item>
      <title>ERROR in extracting date columns with certain format from a library and display only year.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-in-extracting-date-columns-with-certain-format-from-a/m-p/320413#M70567</link>
      <description>&lt;P&gt;hello my below code is extracting date columns having certain format and am displaying only year from the whole date but am facing an error that ---&amp;gt; &lt;BR /&gt;'ERROR: Argument 1 to function YEAR referenced by the %SYSFUNC or %QSYSFUNC macro function is not&lt;BR /&gt; a number.&lt;BR /&gt;ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution&lt;BR /&gt; of %SYSCALL statement or %SYSFUNC or %QSYSFUNC function reference is terminated.&lt;BR /&gt;'&lt;/P&gt;
&lt;P&gt;%macro dteyear(lib=,lib=,outdsn=);&lt;/P&gt;
&lt;P&gt;proc sql noprint;&lt;BR /&gt; select distinct catx(".",libname,memname), name &lt;BR /&gt; into :dsns separated by " ", :varname separated by " "&lt;BR /&gt; from dictionary.columns&lt;BR /&gt; where libname = upcase("&amp;amp;lib") and format=('YYMMDD10.')&lt;BR /&gt; order by 1;&lt;BR /&gt; quit;&lt;BR /&gt;%put &amp;amp;dsns;&lt;BR /&gt;%put &amp;amp;varname;&lt;BR /&gt; %local olddsn curdsn curvbl i;&lt;BR /&gt; data &amp;amp;outdsn.;&lt;BR /&gt; set &lt;BR /&gt; %let olddsn=;&lt;BR /&gt; %do i=1 %to &amp;amp;sqlobs;&lt;BR /&gt; %let curdsn=%scan(&amp;amp;dsns,&amp;amp;i,%str( ));&lt;BR /&gt; %let curvbl=%scan(&amp;amp;varname,&amp;amp;i,%str( ));&lt;BR /&gt; %if &amp;amp;curdsn NE &amp;amp;olddsn&lt;BR /&gt; %then %do;&lt;BR /&gt; %if &amp;amp;olddsn NE&lt;BR /&gt; %then %do;&lt;BR /&gt; )&lt;BR /&gt; %end;&lt;BR /&gt; %let olddsn=&amp;amp;curdsn.;&lt;BR /&gt; &amp;amp;curdsn (keep=&amp;amp;curvbl&lt;BR /&gt; %end;&lt;BR /&gt; %else %do;&lt;BR /&gt; &amp;amp;curvbl&lt;BR /&gt; %end;&lt;BR /&gt; %end;&lt;BR /&gt; );&lt;BR /&gt; %do i=1 %to &amp;amp;sqlobs;&lt;BR /&gt; %scan(&amp;amp;varname,&amp;amp;i,%str( ))=%sysfunc(year("&amp;amp;varname"));&lt;BR /&gt; %end;&lt;BR /&gt; run;&lt;BR /&gt;proc print data=&amp;amp;outdsn;run;&lt;/P&gt;
&lt;P&gt;%MEND prjdteyear;&lt;BR /&gt;%dteyear(lib=dte,outdsn=dteyr);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the input data is as follows&lt;/P&gt;
&lt;P&gt;1975-12-04&amp;nbsp;&lt;BR /&gt;1977-11-03&lt;BR /&gt;1989-09-15&lt;BR /&gt;1998-06-17&lt;BR /&gt;1999-05-31&lt;BR /&gt;2000-08-14&lt;BR /&gt;2001-03-11&lt;BR /&gt;2007-03-11&lt;BR /&gt;2007-12-28&lt;BR /&gt;2008-10-07&lt;BR /&gt;2009-12-03&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;desired output is--&amp;gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1975&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1977&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1989&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1998&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1999&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2000&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2001&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2007&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2007&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2008&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2009&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;any help please? this is urgent matter.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 07:33:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-in-extracting-date-columns-with-certain-format-from-a/m-p/320413#M70567</guid>
      <dc:creator>RTelang</dc:creator>
      <dc:date>2016-12-21T07:33:24Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR in extracting date columns with certain format from a library and display only year.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-in-extracting-date-columns-with-certain-format-from-a/m-p/320416#M70570</link>
      <description>&lt;P&gt;It isn't clear what you have and why you use a macro .&lt;/P&gt;
&lt;P&gt;What's wrong with the simple code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; infile datalines;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; input date yymmdd10.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; year = year(date);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; keep year;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1975-12-04&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1977-11-03&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1989-09-15&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1998-06-17&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1999-05-31&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2000-08-14&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2001-03-11&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2007-03-11&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2007-12-28&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2008-10-07&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2009-12-03&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;; run;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 07:40:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-in-extracting-date-columns-with-certain-format-from-a/m-p/320416#M70570</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-12-21T07:40:51Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR in extracting date columns with certain format from a library and display only year.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-in-extracting-date-columns-with-certain-format-from-a/m-p/320418#M70571</link>
      <description>&lt;P&gt;I have similar questions as posted above, but from technical point of view you need to get rid of %sysfunc around the year.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to also change the format of the column to show correct results. For example the year&amp;nbsp;1975 will have your&amp;nbsp;YYMMDD10. format applied and show as 1965-05-29 in proc print...&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;%macro dteyear(lib=,outdsn=);
proc sql noprint;
select distinct catx(".",libname,memname), name 
into :dsns separated by " ", :varname separated by " "
from dictionary.columns
where libname = upcase("&amp;amp;lib") and format=('YYMMDD10.')
order by 1;
quit;
%put &amp;amp;dsns;
%put &amp;amp;varname;
%local olddsn curdsn curvbl i;
data &amp;amp;outdsn.;
set 
%let olddsn=;
%do i=1 %to &amp;amp;sqlobs;
%let curdsn=%scan(&amp;amp;dsns,&amp;amp;i,%str( ));
%let curvbl=%scan(&amp;amp;varname,&amp;amp;i,%str( ));
%if &amp;amp;curdsn NE &amp;amp;olddsn
%then %do;
%if &amp;amp;olddsn NE
%then %do;
)
%end;
%let olddsn=&amp;amp;curdsn.;
&amp;amp;curdsn (keep=&amp;amp;curvbl
%end;
%else %do;
&amp;amp;curvbl
%end;
%end;
);
%do i=1 %to &amp;amp;sqlobs;
%scan(&amp;amp;varname,&amp;amp;i,%str( ))=year(&amp;amp;varname.);
%end;
run;
proc print data=&amp;amp;outdsn;run;
%MEND;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 07:50:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-in-extracting-date-columns-with-certain-format-from-a/m-p/320418#M70571</guid>
      <dc:creator>chrej5am</dc:creator>
      <dc:date>2016-12-21T07:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR in extracting date columns with certain format from a library and display only year.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-in-extracting-date-columns-with-certain-format-from-a/m-p/320419#M70572</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%sysfunc(year("&amp;amp;varname"))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;can never work. Macro knows only text, so it needs no quotes, therefore the quotes end up in the argument of the year function.&lt;/P&gt;
&lt;P&gt;Even if you omit the quotes, it won't work, as %sysfunc(year()) is evaluated before the data step runs and the variable named by varname exists.&lt;/P&gt;
&lt;P&gt;Since you are creating datastep code at this place in your macro, just write&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%scan(&amp;amp;varname,&amp;amp;i,%str( ))=year(%scan(&amp;amp;varname,&amp;amp;i,%str( )));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to create the assignment statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Be aware that your final dataset will contain lots of missing values if your date variables have different names in the input datasets.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 07:52:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-in-extracting-date-columns-with-certain-format-from-a/m-p/320419#M70572</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-12-21T07:52:54Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR in extracting date columns with certain format from a library and display only year.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-in-extracting-date-columns-with-certain-format-from-a/m-p/320421#M70574</link>
      <description>&lt;P&gt;And PLEASE!&lt;/P&gt;
&lt;P&gt;stop writing such awful spaghetti code. Proper formatting with indentations makes the code much more readable.&lt;/P&gt;
&lt;P&gt;Use the proper icons ({i} and "little running man") to preserve code formatting.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 07:56:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-in-extracting-date-columns-with-certain-format-from-a/m-p/320421#M70574</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-12-21T07:56:52Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR in extracting date columns with certain format from a library and display only year.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-in-extracting-date-columns-with-certain-format-from-a/m-p/320441#M70588</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;  am getting the following output am not getting the specific year values.&lt;BR /&gt;Obs RFDTC &lt;BR /&gt;1 1965-05-19 &lt;BR /&gt;2 1965-05-19 &lt;BR /&gt;3 1965-05-19 &lt;BR /&gt;</description>
      <pubDate>Wed, 21 Dec 2016 09:13:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-in-extracting-date-columns-with-certain-format-from-a/m-p/320441#M70588</guid>
      <dc:creator>RTelang</dc:creator>
      <dc:date>2016-12-21T09:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR in extracting date columns with certain format from a library and display only year.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-in-extracting-date-columns-with-certain-format-from-a/m-p/320444#M70589</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/42231"&gt;@chrej5am&lt;/a&gt; yes i get 1965-05-29 in my proc print how do  i get the original year values?</description>
      <pubDate>Wed, 21 Dec 2016 09:19:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-in-extracting-date-columns-with-certain-format-from-a/m-p/320444#M70589</guid>
      <dc:creator>RTelang</dc:creator>
      <dc:date>2016-12-21T09:19:59Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR in extracting date columns with certain format from a library and display only year.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-in-extracting-date-columns-with-certain-format-from-a/m-p/320446#M70591</link>
      <description>&lt;P&gt;When you apply the YEAR function it returns a NUMBER. You've formatted your years as dates, not numbers.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Format year_var 8.;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 09:28:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-in-extracting-date-columns-with-certain-format-from-a/m-p/320446#M70591</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-12-21T09:28:17Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR in extracting date columns with certain format from a library and display only year.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-in-extracting-date-columns-with-certain-format-from-a/m-p/320451#M70592</link>
      <description>&lt;P&gt;I agree. &amp;nbsp;I have mentioned this many times, however the user appears to be&amp;nbsp;re-writing the enitre Base SAS library in macro only, and is unwilling to post test data or format code.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Dec 2016 09:35:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-in-extracting-date-columns-with-certain-format-from-a/m-p/320451#M70592</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-12-21T09:35:41Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR in extracting date columns with certain format from a library and display only year.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/ERROR-in-extracting-date-columns-with-certain-format-from-a/m-p/320452#M70593</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; it displays 1965 y it doesn't display the specified year.---&amp;gt;&lt;BR /&gt;%scan(&amp;amp;varname,&amp;amp;i,%str( ))=year(%scan(&amp;amp;varname,&amp;amp;i,%str( )));&lt;BR /&gt;				format &amp;amp;varname 8.;</description>
      <pubDate>Wed, 21 Dec 2016 09:35:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/ERROR-in-extracting-date-columns-with-certain-format-from-a/m-p/320452#M70593</guid>
      <dc:creator>RTelang</dc:creator>
      <dc:date>2016-12-21T09:35:42Z</dc:date>
    </item>
  </channel>
</rss>

