<?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: find min and max of the date per subject in entire library in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/965165#M375802</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466333"&gt;@SAS-PD&lt;/a&gt;&amp;nbsp;, have you figured out and solved your question? I write a macro to convert all tables with all columns of character date values to numeric (I assume that in your raw datasets, all date variables are character type, and I write the macro base on this condition). But &lt;STRONG&gt;some major problems need to be solved before use this macro&lt;/STRONG&gt;: 1) because I used a nested do loop, it produced 2*3=6 tables (in fact I do not know why it is 6, I thought it should be 2*4=8), i.e., for each of my raw data table, it produced two more duplicates. Also, each time I run this macro again, it produced new variables and tables according to the statement and make more duplicates of the datasets and variables. Without solve this problem the macro cannot be used because it causes mess by the duplications, 2) I am not sure if I should use any %local statement inside the macro to prevent it overwrite any macro variable that already has that macro name,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;, could you please take a look on my code and offer some suggestions and modification, thanks very much! And&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466333"&gt;@SAS-PD&lt;/a&gt;&amp;nbsp;, could you please let me know if this solve your questions, thanks a lot!&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data vdraw1;
   input subjid $ var5 $ var6 $ v11dat $ 
         v12dat $ v13dat $;
   datalines;
subj1 xxx sy 01/01/21 01/01/22 01/01/23
subj2 xttx ry 02/01/21 02/01/22 02/01/23
;
run;
proc print data=vdraw1;run;
data vdraw2;
   input subjid $ var3 $ v21dat $;
   datalines;
subj1 xx 02/02/02
subj2 z .
;
run;
proc print data=vdraw2;run;
proc sql;
select distinct memname
   into :table1-
   from dictionary.columns
   where libname='WORK' and
         memname like 'VDRAW%' and
         name like '%dat';
quit;
%let tableobs=&amp;amp;sqlobs;
%put &amp;amp;tableobs;
proc sql;
select distinct name
   into :var1-
   from dictionary.columns
   where libname='WORK' and
         memname like 'VDRAW%' and
         name like '%dat';
quit;
%let varobs=&amp;amp;sqlobs;
%put &amp;amp;varobs;
%macro char2num;
%do i=1 %to &amp;amp;tableobs;
data &amp;amp;&amp;amp;table&amp;amp;i.._num;
   set &amp;amp;&amp;amp;table&amp;amp;i;
   %do j=1 %to &amp;amp;varobs;
   &amp;amp;&amp;amp;var&amp;amp;j.._num=input(&amp;amp;&amp;amp;var&amp;amp;j,mmddyy10.);
   %end;
run;
proc print data=&amp;amp;&amp;amp;table&amp;amp;i.._num;
proc contents data=&amp;amp;&amp;amp;table&amp;amp;i.._num;
%end;
%mend char2num;
%char2num;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_0-1745679893951.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106533iAEC62CD7DDC13DF5/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_0-1745679893951.png" alt="dxiao2017_0-1745679893951.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_1-1745680278757.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106534i087805E431AFF19B/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_1-1745680278757.png" alt="dxiao2017_1-1745680278757.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_2-1745680469747.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106535iDCD68237856740D7/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_2-1745680469747.png" alt="dxiao2017_2-1745680469747.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_3-1745680562540.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106536i3FF3C2B55E34444B/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_3-1745680562540.png" alt="dxiao2017_3-1745680562540.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_4-1745680676173.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106537i3BF87C73527A48F0/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_4-1745680676173.png" alt="dxiao2017_4-1745680676173.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Another thing I would like to mention is that,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466333"&gt;@SAS-PD&lt;/a&gt;&amp;nbsp;, in your raw datasets, the informat and format of the date variables are not consistent, I marked it out (see picture), the informat is &lt;EM&gt;ddmmyy.&lt;/EM&gt;, the format is &lt;EM&gt;mmddyy.&lt;/EM&gt;, i.e., the date and month are reversed and confusing without knowing which is month and which is date.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106538iEAA9239C1CCD75FD/image-size/large?v=v2&amp;amp;px=999" role="button" title="Untitled.png" alt="Untitled.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;</description>
    <pubDate>Sat, 26 Apr 2025 15:35:02 GMT</pubDate>
    <dc:creator>dxiao2017</dc:creator>
    <dc:date>2025-04-26T15:35:02Z</dc:date>
    <item>
      <title>find min and max of the date per subject in entire library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964624#M375663</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to find min and max of the date per subject from all datasets in a library&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have created I have created DateVariables dataset using proc content to list all date variables from&amp;nbsp;table1 and table2.&lt;/P&gt;&lt;P&gt;*Want1;&lt;/P&gt;&lt;P&gt;*I would like to list all dates available for the subject in entire library;&lt;BR /&gt;/*subjID date11 date12 date13 date21 ...(all dates available)*/&lt;/P&gt;&lt;P&gt;subjID date11 date12 date13 date21&lt;BR /&gt;---------------------------------------------------------------------------&lt;BR /&gt;subj1 01/01/21 01/01/22 01/01/23 02/02/02&lt;BR /&gt;subj2 02/01/21 02/01/22 02/01/23&lt;/P&gt;&lt;P&gt;*want2;&lt;BR /&gt;*find min and max of the date by subjID ;&lt;/P&gt;&lt;P&gt;subjID date_min date_max&lt;BR /&gt;------------------------------------------------------------&lt;BR /&gt;subj1 02/02/02 01/01/23&lt;BR /&gt;subj2 02/01/21 02/01/23&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data d_test.table1;&lt;BR /&gt;infile datalines ;&lt;BR /&gt;input subjID $ ar5 $ var6 $ date11: ddmmyy10. date12: ddmmyy10. date13: ddmmyy10.;&lt;BR /&gt;format date11 mmddyy10. date12 mmddyy10. date13 mmddyy10.;&lt;BR /&gt;datalines;&lt;BR /&gt;subj1 xxx sy 01/01/21 01/01/22 01/01/23&lt;BR /&gt;subj2 xttx ry 02/01/21 02/01/22 02/01/23&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data d_test.table2;&lt;BR /&gt;infile datalines ;&lt;BR /&gt;input subjID $ var3 $ date21: ddmmyy10.;&lt;BR /&gt;format date21 mmddyy10.;&lt;BR /&gt;datalines;&lt;BR /&gt;subj1 xx 02/02/02&lt;BR /&gt;subj2 z .&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;*list all date variables from&amp;nbsp;table1 and table2;&lt;BR /&gt;data d_test.DateVariables;&lt;BR /&gt;infile datalines ;&lt;BR /&gt;input table $ varname $ ;&lt;BR /&gt;datalines;&lt;BR /&gt;table1 date11&lt;BR /&gt;table1 date12&lt;BR /&gt;table1 date13&lt;BR /&gt;table2 date21&lt;BR /&gt;table3 date31&lt;BR /&gt;table3 date32&lt;BR /&gt;table3 date33&lt;BR /&gt;table3 date34&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your guidance!&lt;/P&gt;</description>
      <pubDate>Fri, 18 Apr 2025 18:56:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964624#M375663</guid>
      <dc:creator>SAS-PD</dc:creator>
      <dc:date>2025-04-18T18:56:40Z</dc:date>
    </item>
    <item>
      <title>Re: find min and max of the date per subject in entire library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964626#M375665</link>
      <description>&lt;P&gt;Getting the min/max is pretty simple.&lt;/P&gt;
&lt;P&gt;Let's make your example datasets first.&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
  input subjID $ ar5 $ var6 $ (date11 - date13) (:ddmmyy.);
format date11-date13 date9. ;
datalines;
subj1 xxx sy 01/01/21 01/01/22 01/01/23
subj2 xttx ry 02/01/21 02/01/22 02/01/23
;

data table2;
  input subjID $ var3 $ date21 :ddmmyy.;
  format date21 date9.;
datalines;
subj1 xx 02/02/02
subj2 z .
;

data DateVariables;
  input (table varname) (:$32.) ;
datalines;
table1 date11
table1 date12
table1 date13
table2 date21
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;Now we just need to get the dataset list and variable list from your metadata table.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select distinct varname into :varlist separated by ' ' from DateVariables;
select distinct table into :dslist separated by ' ' from DateVariables;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To be able to generate a dataset to find the min/max over all date variables in all datasets in one step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set &amp;amp;dslist ;
  by subjid;
  array _dates &amp;amp;varlist ;
  if first.subjid then do;
    min=.;max=.;
  end;
  retain min max;
  min=min(of min &amp;amp;varlist);
  max=max(of max &amp;amp;varlist);
  if last.subjid;
  keep subjid min max;
  format min max date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;       subj
Obs     ID            min          max

 1     subj1    02FEB2002    01JAN2023
 2     subj2    02JAN2021    02JAN2023

&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Apr 2025 19:11:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964626#M375665</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-04-18T19:11:23Z</dc:date>
    </item>
    <item>
      <title>Re: find min and max of the date per subject in entire library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964756#M375698</link>
      <description>&lt;P&gt;Thank you, Tom!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I apologize...I think I gave wrong sample datasets as date variables name is not static.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I am trying to find min and max of the date per subject from all datasets in a library where variable ends with 'DAT'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;in one library, I have 50+ datasets that has 120+ date variables named with 'DAT'&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Among all those 120+ dates I need to find out min and max of the date per subject &lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 21 Apr 2025 15:26:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964756#M375698</guid>
      <dc:creator>SAS-PD</dc:creator>
      <dc:date>2025-04-21T15:26:39Z</dc:date>
    </item>
    <item>
      <title>Re: find min and max of the date per subject in entire library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964761#M375699</link>
      <description>&lt;P&gt;You said you had already solved the issue of finding the list of variables to use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you need help with that?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so the FMTINFO() function and the 'CAT' option will help.&amp;nbsp; I would recommend using PROC CONTENTS to get the list of variables since it will provide the bare format name required to use that function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=mylib._all_ noprint out=contents; run;
proc sql noprint;
create table DateVariables as 
  select memname,name 
  from contents
  where 'date'=fmtinfo(format,'cat')
  group by memname
  having 1=max(upcase(name)='SUBJID')
  order by memname,name
;
select distinct memname into :dslist separated by ' ' from DateVariables;
select distinct nliteral(name) into :varlist separated by ' ' from DateVariables;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 Apr 2025 15:48:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964761#M375699</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-04-21T15:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: find min and max of the date per subject in entire library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964841#M375722</link>
      <description>&lt;P&gt;Thanks again!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code works with test data, however while using my datasets it is giving ERROR: BY variables are not properly sorted on data set&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please guide?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Apr 2025 15:20:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964841#M375722</guid>
      <dc:creator>SAS-PD</dc:creator>
      <dc:date>2025-04-22T15:20:12Z</dc:date>
    </item>
    <item>
      <title>Re: find min and max of the date per subject in entire library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964842#M375723</link>
      <description>&lt;P&gt;The code assumes the individual datasets were already sorted by SUBJID since that was your KEY variable.&lt;/P&gt;
&lt;P&gt;You could add code to sort the datasets (or index them) before the final data step.&lt;/P&gt;
&lt;P&gt;You could change the code to collect the individual observation level min/max values and then use another step like PROC SUMMARY to produce the overall min/max per SUBJID.&amp;nbsp; You could even make the first step be a VIEW instead of a physical dataset to reduce the amount of diskspace you use.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data details/view=details;
  set &amp;amp;dslist ;
  min=min(of min &amp;amp;varlist);
  max=max(of max &amp;amp;varlist);
  keep subjid min max;
  format min max date9.;
run;
proc summary data=details nway;
  class subjid;
  var min max;
  output out=want min(min)=min max(max)=max;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Apr 2025 15:25:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964842#M375723</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-04-22T15:25:39Z</dc:date>
    </item>
    <item>
      <title>Re: find min and max of the date per subject in entire library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964848#M375724</link>
      <description>&lt;P&gt;Thank you for all the explanation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;now, I am getting&amp;nbsp;&lt;/P&gt;&lt;P&gt;Invalid numeric data, testDAT='6/6/2023' error&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All my dates are char&amp;nbsp;$24.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Apr 2025 17:13:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964848#M375724</guid>
      <dc:creator>SAS-PD</dc:creator>
      <dc:date>2025-04-22T17:13:16Z</dc:date>
    </item>
    <item>
      <title>Re: find min and max of the date per subject in entire library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964852#M375728</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466333"&gt;@SAS-PD&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you for all the explanation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;now, I am getting&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Invalid numeric data, testDAT='6/6/2023' error&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All my dates are char&amp;nbsp;$24.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then they are NOT dates.&amp;nbsp; They are character strings.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error message is probably from the SAS data step trying to autoconvert that string into a number using the normal numeric informat.&lt;/P&gt;
&lt;PRE&gt;1    data test;
2      string='6/6/2025';
3      min = min(of min string);
4    run;

NOTE: Character values have been converted to numeric
      values at the places given by: (Line):(Column).
      3:20
NOTE: Invalid numeric data, string='6/6/2025' , at line 3 column 20.
string=6/6/2025 min=. _ERROR_=1 _N_=1
NOTE: Missing values were generated as a result of performing an operation on
      missing values.
      Each place is given by: (Number of times) at (Line):(Column).
      1 at 3:9
NOTE: The data set WORK.TEST has 1 observations and 2 variables.
&lt;/PRE&gt;
&lt;P&gt;Did you use the code I posted to find the variable based on the type of FORMAT that was attached them?&amp;nbsp; It would not have found that variable since it should not have had a DATE type format attached.&amp;nbsp; &amp;nbsp;Or if it did then you would get an error message when trying to use that dataset that character format named $DATE (or $MMDDYY) did not exist because SAS will automatically prefix the $ to any format attached to a character variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it possible that the same variable name is character in one dataset and numeric in another?&amp;nbsp; If so then how were the dataset in the libref created?&amp;nbsp; Do you perhaps let PROC IMPORT automatically guess what type of variable to create?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you do want to treat the character string like '6/6/2025' as a DATE you will need to add pre-processing step to make a numeric variable from it.&amp;nbsp; And you will need to decide if the first 6 represent the month of the year of the day of the month to decide which INFORMAT to use to convert that string into a date.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Apr 2025 17:54:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964852#M375728</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-04-22T17:54:28Z</dc:date>
    </item>
    <item>
      <title>Re: find min and max of the date per subject in entire library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964871#M375731</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;, base on your code, I made minor changes, this is my version: (1) I use a &lt;EM&gt;proc sql; select into :varlist&amp;nbsp;&lt;/EM&gt;step with &lt;EM&gt;dictionary.columns&lt;/EM&gt; instead of the original&amp;nbsp;&lt;EM&gt;proc contents&lt;/EM&gt; step and your &lt;EM&gt;proc sql&lt;/EM&gt; step (and this is for solve &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466333"&gt;@SAS-PD&lt;/a&gt;&amp;nbsp;'s question that the columns' name are end with '&lt;EM&gt;DAT&lt;/EM&gt;'), (2) add a &lt;EM&gt;proc sort&lt;/EM&gt; step to solve the possible error msg of&amp;nbsp;&lt;EM&gt;by var are not properly sorted&lt;/EM&gt;. I tried to avoid using array (because I never used array the way in your code and it is a bit advanced for me, so I was going to use the simple SAS/base min() and max() functions instead) in the last step but was not able to find a simpler solution, and thus I think array in your code is the best (or necessary or only) solution to find the min and max value for several date columns in the &amp;amp;varlist macro, (3) create an intermediate dataset (that serves as an analysis dataset base on which to produce the final reports or tables) to be used in your &lt;EM&gt;data want; set &amp;amp;dslist&lt;/EM&gt; step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data vdraw1;
   input subjid $ var5 $ var6 $ v11dat v12dat v13dat;
   informat v11dat v12dat v13dat ddmmyy.;
   format v11dat v12dat v13dat date9.;
   datalines;
subj1 xxx sy 01/01/21 01/01/22 01/01/23
subj2 xttx ry 02/01/21 02/01/22 02/01/23
;
run;
proc print data=vdraw1;run;
data vdraw2;
   input subjid $ var3 $ v21dat ddmmyy8.;
   format v21dat date9.;
   datalines;
subj1 xx 02/02/02
subj2 z .
;
run;
proc print data=vdraw2;run;
proc sql;
select memname,
       name
   into :dslist separated by ' ',
        :varlist separated by ' '
   from dictionary.columns
   where libname='WORK' and
         memname like 'VDRAW%' and
         name like '%dat';
quit;
data vdate;
   set &amp;amp;dslist;
   keep subjid &amp;amp;varlist;
run;
proc print data=vdate;run;
proc sort data=vdate out=vdsort nodup;
   by subjid;
run;
proc print data=vdsort;run;
data vdfinal;
   set vdsort;
   by subjid;
   array vds &amp;amp;varlist;
   if first.subjid then do;
      min=.;
      max=.;
   end;
   retain min max;
   min=min(of min &amp;amp;varlist);
   max=max(of max &amp;amp;varlist);
   if last.subjid;
   keep subjid min max;
   format min max date9.;
run;
proc print data=vdfinal;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_0-1745362880962.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106427i204E2F65C5FC06B9/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_0-1745362880962.png" alt="dxiao2017_0-1745362880962.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_2-1745362978474.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106429iBBF2ED6AE96100EB/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_2-1745362978474.png" alt="dxiao2017_2-1745362978474.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_3-1745363062918.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106430i5059498A0C7764E8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dxiao2017_3-1745363062918.png" alt="dxiao2017_3-1745363062918.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Apr 2025 23:42:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964871#M375731</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-04-22T23:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: find min and max of the date per subject in entire library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964874#M375732</link>
      <description>&lt;P&gt;Your code is not even trying to find the actual DATE variables.&amp;nbsp; Instead it is selecting based on the NAME of the variable.&amp;nbsp;&amp;nbsp;That is probably why you ended up selecting a character variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using DICTIONARY.COLUMNS will make it harder to find the actual DATE variable.&amp;nbsp; That is because in DICTIONARy.COLUMNS the value of FORMAT for your date variables will be 'DATE9.' which is NOT compatible for passing to the FMTINFO() function.&amp;nbsp; You can add some extra code to strip the digits and period from the end of FORMAT value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;fmtinfo(prxchange('s/\d*\.*\d*$//',-1,trim(format)),'cat')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The ARRAY statemen tis not needed, as your code shows.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Apr 2025 00:29:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964874#M375732</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-04-23T00:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: find min and max of the date per subject in entire library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964876#M375733</link>
      <description>&lt;P&gt;Thank you very much for telling me the standard and most accurate way to find the actual DATE variables, which uses &lt;EM&gt;fmtinfo()='date'&lt;/EM&gt; as the only criteria. I'll learn to use this function later on. However, in this case, I think the rule should not be so rigid, because it is only a small library that contains 50+ datesets with 120+ date variables, and the variable names are clearly defined (end with 'DAT'). Use dictionary.columns should be sufficient and accurate enough to find out the date variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are right about that the array was not needed, in fact I myself wondered why the array was used that way (in the statements followed there was even no anything referred to the array name, and I thought that was an advanced technique that I should learn it later), meanwhile I was thinking to apply same calculation on a set of variables, array is the right choice, and thus I did not find that the array was not necessary and was not used in the proper way. I deleted the array statement and the result is the same:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data vdfinal;
   set vdsort;
   by subjid;
   if first.subjid then do;
      min=.;
      max=.;
   end;
   retain min max;
   min=min(of min &amp;amp;varlist);
   max=max(of max &amp;amp;varlist);
   if last.subjid;
   keep subjid min max;
   format min max date9.;
run;
proc print data=vdfinal;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_0-1745371143660.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106431i16DD3120C2907C1E/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_0-1745371143660.png" alt="dxiao2017_0-1745371143660.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Apr 2025 01:23:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964876#M375733</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-04-23T01:23:07Z</dc:date>
    </item>
    <item>
      <title>Re: find min and max of the date per subject in entire library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964877#M375734</link>
      <description>&lt;P&gt;And since array is not needed here, an amendment to my previous thread: the best solution here to find out each subject's min and max values for a set of date variables in a &amp;amp;varlist macro is the &lt;EM&gt;by&lt;/EM&gt; var and &lt;EM&gt;if.first/if.last&lt;/EM&gt; method you used in your answer. I thought to use &lt;EM&gt;array&lt;/EM&gt; or &lt;EM&gt;sql&lt;/EM&gt; but did not come up with an optimal solution. &lt;EM&gt;Proc means&lt;/EM&gt; works but need to produce one more dataset and need one more step to apply &lt;EM&gt;date9.&lt;/EM&gt; format to the date values.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Apr 2025 02:17:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964877#M375734</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-04-23T02:17:09Z</dc:date>
    </item>
    <item>
      <title>Re: find min and max of the date per subject in entire library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964961#M375741</link>
      <description>&lt;P&gt;Thank you, Tom!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I changed the code to take dates that are ending with DAT as per requirement and those happens to be character string dates (example 4/26/2023).&amp;nbsp; what changes to be made in code to convert all those character dates to&amp;nbsp;resolve the error?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Apr 2025 14:54:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964961#M375741</guid>
      <dc:creator>SAS-PD</dc:creator>
      <dc:date>2025-04-23T14:54:29Z</dc:date>
    </item>
    <item>
      <title>Re: find min and max of the date per subject in entire library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964963#M375742</link>
      <description>&lt;P&gt;The main thing is you would need to add code to convert the string to a date.&amp;nbsp; Once you have a date you could then check if for min/max values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Say you have a variable named CHAR_DAT in a dataset name HAVE.&lt;/P&gt;
&lt;P&gt;You could make a new dataset named WANT that adds a variable named NUM_DAT by using code something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  num_dat = input(char_dat,mmddyy10.);
  format num_dat date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The INPUT() function uses an INFORMAT to convert text strings into values. When you use a numeric informat, like MMDDYY, then the value is numeric.&amp;nbsp; If your strings are actually in DMY order instead of the MDY order that MMDDYY informat understands then use the DDMMYY informat instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you never have cases where the same variable name, day VISIT_DAT, exists &lt;STRONG&gt;as character in one dataset and numeric in another&lt;/STRONG&gt; then you might be able to extend your current code by making two macro variables with the variable lists.&amp;nbsp; One for the numeric date variables and other for the character ones.&amp;nbsp; Then you could use that build the step that gathers the individual observations.&amp;nbsp; Note for this an array is required.&lt;/P&gt;
&lt;P&gt;So if you created the macro variables DSLIST and CHARLIST and NUMLIST then the step to combine all of the dataset could look like this.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data vdate;
  set &amp;amp;dslist;
  array _char_ &amp;amp;charlist;
  do over _char_ ;
    min=min(min,input(_char_,mmddyy10.));
    max=max(max,input(_char_,mmddyy10.));
  end;
  min=min(of min &amp;amp;numlist);
  max=max(of max &amp;amp;numlist);
  format min max date9.;
  keep subjid min max /* &amp;amp;charlist &amp;amp;numlist */ ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you do have the same variable exist as different types then you need to treat each dataset separately.&amp;nbsp; At that point I would probably just use the dataset with the list of tables and variables to drive the writing of code.&amp;nbsp; So you might have it write a series of steps like this that will gather the min/max observations for a dataset and then append them into a summary dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data min_max;
  set TABLE1 ;
  min=min(NUMVAR1,NUMVAR2,input(CHARVAR1,mmddyy10.));
  max=max(NUMVAR1,NUMVAR2,input(CHARVAR1,mmddyy10.));
  format min max date9.;
  if n(min,max);
  keep subjid min max;
run;
proc append base=VDATE data=min_max force;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So the next one might reference different variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data min_max;
  set TABLE2 ;
  min=min(NUMVAR2,input(CHARVAR2,mmddyy10.));
  max=max(NUMVAR2,input(CHARVAR2,mmddyy10.));
  format min max date9.;
  if n(min,max);
  keep subjid min max;
run;
proc append base=VDATE data=min_max force;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you have done that for all of your dataset with DAT variables you will have a similar VDATE dataset you can then collapse to one observation per SUBJID.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Apr 2025 15:29:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964963#M375742</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-04-23T15:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: find min and max of the date per subject in entire library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964975#M375748</link>
      <description>&lt;P&gt;Thanks for explaining all the scenarios.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to check those DAT variables only? That way I will only have all character dates to find min and max? Also, how do I create&amp;nbsp;&lt;SPAN&gt;CHARLIST and NUMLIST macro variable?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Apr 2025 17:58:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/964975#M375748</guid>
      <dc:creator>SAS-PD</dc:creator>
      <dc:date>2025-04-23T17:58:26Z</dc:date>
    </item>
    <item>
      <title>Re: find min and max of the date per subject in entire library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/965032#M375771</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;, base on your code, suggestion, and comments, I modified the code in my previous thread to deal with the character date value problem (an array was added to convert character date values to numeric date values&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":neutral_face:"&gt;😐&lt;/span&gt;PS: I should be able to post this thread much more earlier when those date values had been converted to numeric, but I spent too much time on an unnecessary step, which was to display the converted numeric date values in &lt;EM&gt;date9.&lt;/EM&gt; format and to change the data &lt;EM&gt;type, informat&lt;/EM&gt; and &lt;EM&gt;format&lt;/EM&gt; to &lt;EM&gt;numeric&lt;/EM&gt; or &lt;EM&gt;date&lt;/EM&gt;, as those numeric date columns was still character type in the &lt;EM&gt;proc contents&lt;/EM&gt; table&lt;span class="lia-unicode-emoji" title=":neutral_face:"&gt;😐&lt;/span&gt; and I still have not figure out it&lt;span class="lia-unicode-emoji" title=":neutral_face:"&gt;😐&lt;/span&gt;, data &lt;EM&gt;type, format, informat&lt;/EM&gt;&amp;nbsp;are always pain). Hope this solve&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466333"&gt;@SAS-PD&lt;/a&gt;&amp;nbsp;'s question. Code and results are as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data vdraw1;
   input subjid $ var5 $ var6 $ v11dat $ 
         v12dat $ v13dat $;
   datalines;
subj1 xxx sy 01/01/21 01/01/22 01/01/23
subj2 xttx ry 02/01/21 02/01/22 02/01/23
;
run;
proc print data=vdraw1;run;
data vdraw2;
   input subjid $ var3 $ v21dat $;
   datalines;
subj1 xx 02/02/02
subj2 z .
;
run;
proc print data=vdraw2;run;
proc sql;
select memname,
       name
   into :dslist separated by ' ',
        :varlist separated by ' '
   from dictionary.columns
   where libname='WORK' and
         memname like 'VDRAW%' and
         name like '%dat';
quit;
data vdate;
   set &amp;amp;dslist;
   keep subjid &amp;amp;varlist;
run;
proc print data=vdate;run;
proc sort data=vdate out=vdsort nodup;
   by subjid;
run;
proc print data=vdsort;run;
data vdfmtchg;
   set vdsort;
   array dfmtchg[*] &amp;amp;varlist;
   do i=1 to dim(dfmtchg);
      dfmtchg[i]=input(dfmtchg[i],ddmmyy10.);
   end;
   drop i;
run;
proc print data=vdfmtchg;run;
data vdfinal;
   set vdfmtchg;
   by subjid;
   if first.subjid then do;
      min=.;
      max=.;
   end;
   retain min max;
   min=min(of min &amp;amp;varlist);
   max=max(of max &amp;amp;varlist);
   if last.subjid;
   keep subjid min max;
   format min max date9.;
run;
proc print data=vdfinal;run;         &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_0-1745496875616.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106485i5FA67A78BB929C50/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_0-1745496875616.png" alt="dxiao2017_0-1745496875616.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_3-1745497278773.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106489i0A72A486E3AC8860/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_3-1745497278773.png" alt="dxiao2017_3-1745497278773.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dxiao2017_2-1745496970619.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106487i8FE20D254D1CFFB1/image-size/large?v=v2&amp;amp;px=999" role="button" title="dxiao2017_2-1745496970619.png" alt="dxiao2017_2-1745496970619.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Apr 2025 15:22:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/965032#M375771</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-04-24T15:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: find min and max of the date per subject in entire library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/965043#M375775</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466333"&gt;@SAS-PD&lt;/a&gt;&amp;nbsp;, according to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;'s code and comments, I modified my version of code (in the last thread, the data type in the raw data has been changed to $ and an array was added to convert it to numeric using the same &amp;amp;varlist macro variable) to solve your question of convert character data type to numeric for date variables. Could you please let me know if it solve your question, thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 24 Apr 2025 15:52:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/965043#M375775</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-04-24T15:52:58Z</dc:date>
    </item>
    <item>
      <title>Re: find min and max of the date per subject in entire library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/965064#M375778</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466238" target="_blank" rel="noopener"&gt;dxiao2017 ,&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for looking into this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While creating vdfmtchg, I am getting below error now ...&lt;/P&gt;&lt;P&gt;NOTE: Numeric values have been converted to character&lt;BR /&gt;values at the places given by: (Line):(Column).&lt;BR /&gt;64:7&lt;BR /&gt;NOTE: Invalid argument to function INPUT at line 64 column 18.&lt;/P&gt;&lt;P&gt;-------------------------------------&lt;/P&gt;&lt;P&gt;could it be due to some dates has uu or u or (alphabets) in char dates? If so, how do I solve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for following up!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 24 Apr 2025 17:30:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/965064#M375778</guid>
      <dc:creator>SAS-PD</dc:creator>
      <dc:date>2025-04-24T17:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: find min and max of the date per subject in entire library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/965117#M375795</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466333"&gt;@SAS-PD&lt;/a&gt;&amp;nbsp;, thanks a lot for reply me!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think your problem is about converting the date variables to real numeric type, i.e., the data type in the &lt;EM&gt;proc content&lt;/EM&gt; table is numeric or date type, not character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my code, although the date values had been converted to numeric that can be used in calculation (you can see they are numeric values as the missing values were displayed as dot), the data type in the &lt;EM&gt;proc contents&lt;/EM&gt; table was still character, also, when look at the attributions of those date variables, they did not have any informat or format, and the data type was character. And this is the problem. As I mentioned in previous thread, I was going to convert those columns in this data table to real numeric ones and tried but did not figure out. One thing I thought can solve the problem but did not try is using a data step to reset the data table and convert those columns to numeric type, like this (&lt;STRONG&gt;I did not try it and the code are not correct&lt;/STRONG&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data numtype;
   infile datalines;
   informat &amp;amp;varlist infromats.;
   format &amp;amp;varlist formats.;
   set chartype;
   datalines;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;One thing to do is perhaps add a $ after the array name, like this (&lt;STRONG&gt;I did not run it the and maybe the code cannot run through&lt;/STRONG&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data vdfmtchg;
   set vdsort;
   array dfmtchg[*] $ &amp;amp;varlist;
   do i=1 to dim(dfmtchg);
      dfmtchg[i]=input(dfmtchg[i],ddmmyy10.);
   end;
   drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I think this does not solve the problem because the dfmtchg[i] I want to create is numeric, and this $ sign will make SAS confused. Another thing I can think is add another numeric array to create a set of new column, which convert the column in &amp;amp;varlist to numeric, but this also I did not try it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I do not know what are the "&lt;EM&gt;uu or u or (alphabets) in char dates&lt;/EM&gt;" you talk about, but I guess it is still the problem of data type. &lt;STRONG&gt;One thing to do is inspect and improve your raw datasets&lt;/STRONG&gt;, you only have 50+ datasets and 120+ variables, you can inspect what's wrong/not consistent with the data informats, formats, data type, and column values first (using &lt;EM&gt;proc content, proc freq&lt;/EM&gt; or whatever basic steps), and then decide what is the next step, &lt;STRONG&gt;the first thing to do may be make all raw datasets consistent and clean&lt;/STRONG&gt;. To conclude, I think the problem is the raw data, if all columns and values in the raw data are conformed to a consistent standard or rule, there would be no such complex problem in the consecutive data editing and analyzing steps.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Apr 2025 15:37:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/965117#M375795</guid>
      <dc:creator>dxiao2017</dc:creator>
      <dc:date>2025-04-25T15:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: find min and max of the date per subject in entire library</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/965126#M375796</link>
      <description>&lt;P&gt;This step does not make any sense if the variables are CHARACTER.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data vdfmtchg;
   set vdsort;
   array dfmtchg[*] &amp;amp;varlist;
   do i=1 to dim(dfmtchg);
      dfmtchg[i]=input(dfmtchg[i],ddmmyy10.);
   end;
   drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Because the INPUT() funciton is going to return a NUMBER which you then assign back to the CHARACTER variable.&amp;nbsp; So at that point SAS will user the BEST12. format to convert the number of days the INPUT() function calculated into the digit strings you saw in your printout.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1745595837209.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106520i1E191DDA870AC6F8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1745595837209.png" alt="Tom_0-1745595837209.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;You cannot tell it since ODS output windows "eat" the leading spaces but the values your character variables look like:&lt;/P&gt;
&lt;PRE&gt;       22281
           .&lt;/PRE&gt;
&lt;P&gt;Since the BEST12. format will right align the digit strings in the 12 characters it writes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only reason it worked is because you later asked the MIN() function to find the minimum value of these character variables.&amp;nbsp; But the MIN() function only works on NUMBERS.&amp;nbsp; So SAS used the 32. informat to convert those 12 character strings back into numbers.&amp;nbsp; Which you then attached the DATE9. format to so that they printed in a way that humans could understand them as representing dates.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Apr 2025 15:47:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-min-and-max-of-the-date-per-subject-in-entire-library/m-p/965126#M375796</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-04-25T15:47:44Z</dc:date>
    </item>
  </channel>
</rss>

