<?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: Calculating age from two date string variables in YYYYMMDD in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931065#M366300</link>
    <description>&lt;P&gt;Not working" is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the "&amp;lt;/&amp;gt;" to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "&amp;lt;/&amp;gt;" icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once a variable is created in SAS you cannot change its' type. Since DOB and Sample_dt are character the INPUT to "change" them to numeric date values fails.&lt;/P&gt;
&lt;P&gt;Also your first data step does not create the variables as character causing other issues as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So create new variables from the character versions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
   input dob $  sample_dt $ ;
datalines;
19650214    20100429
19800724    20210823
19991208    20090908
;

data want;
   set have;
   newdob=input(dob, yymmdd8.);
   newsample_dt=input(sample_dt, yymmdd8.);
   age=yrdif(newdob, newsample_dt);
   format newdob newsample_dt yymmdd8.;
run;&lt;/PRE&gt;
&lt;P&gt;If you want age to be an integer then use to remove the decimal portion of age.&lt;/P&gt;
&lt;PRE&gt;age= floor (yrdif(newdob, newsample_dt) );&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 05 Jun 2024 22:23:19 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2024-06-05T22:23:19Z</dc:date>
    <item>
      <title>Calculating age from two date string variables in YYYYMMDD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931063#M366298</link>
      <description>&lt;P&gt;I have the following dataset&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;
   input dob   sample_dt ;
datalines;&lt;BR /&gt;19650214    20100429&lt;BR /&gt;19800724    20210823&lt;BR /&gt;19991208    20090908&lt;BR /&gt;;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;DIV class=""&gt;I want to calculate the age in years based on dob and sample_dt. Looking for the following output&lt;/DIV&gt;&lt;DIV class=""&gt;dob&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sample_dt&amp;nbsp; &amp;nbsp; &amp;nbsp;age&lt;BR /&gt;19650214&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20100429&amp;nbsp; &amp;nbsp; &amp;nbsp; 45&lt;BR /&gt;19800724&amp;nbsp; &amp;nbsp; &amp;nbsp; 20210623&amp;nbsp; &amp;nbsp; &amp;nbsp; 40&lt;BR /&gt;19991208&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20090908&amp;nbsp; &amp;nbsp; &amp;nbsp;09&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;I tried the following code but its not working.&lt;/DIV&gt;&lt;DIV class=""&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;dob=input(dob, yymmdd8.);&lt;BR /&gt;sample_dt=input(sample_dt, yymmdd8.);&lt;BR /&gt;age=yrdif(dob, sample_dt);&lt;BR /&gt;format dob sample_dt yymmdd8.;&lt;BR /&gt;run;&lt;/DIV&gt;</description>
      <pubDate>Wed, 05 Jun 2024 22:13:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931063#M366298</guid>
      <dc:creator>SASPreK</dc:creator>
      <dc:date>2024-06-05T22:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age from two date string variables in YYYYMMDD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931065#M366300</link>
      <description>&lt;P&gt;Not working" is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the "&amp;lt;/&amp;gt;" to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "&amp;lt;/&amp;gt;" icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once a variable is created in SAS you cannot change its' type. Since DOB and Sample_dt are character the INPUT to "change" them to numeric date values fails.&lt;/P&gt;
&lt;P&gt;Also your first data step does not create the variables as character causing other issues as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So create new variables from the character versions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
   input dob $  sample_dt $ ;
datalines;
19650214    20100429
19800724    20210823
19991208    20090908
;

data want;
   set have;
   newdob=input(dob, yymmdd8.);
   newsample_dt=input(sample_dt, yymmdd8.);
   age=yrdif(newdob, newsample_dt);
   format newdob newsample_dt yymmdd8.;
run;&lt;/PRE&gt;
&lt;P&gt;If you want age to be an integer then use to remove the decimal portion of age.&lt;/P&gt;
&lt;PRE&gt;age= floor (yrdif(newdob, newsample_dt) );&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2024 22:23:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931065#M366300</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-06-05T22:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age from two date string variables in YYYYMMDD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931067#M366301</link>
      <description>&lt;P&gt;"Not working" on its own is not helpful (to be&amp;nbsp;&lt;U&gt;very&lt;/U&gt; polite).&lt;/P&gt;
&lt;P&gt;Describe in detail what does not meet your expectations, and post the log from the code into a window opened with the &amp;lt;/&amp;gt; button.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2024 22:25:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931067#M366301</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-06-05T22:25:16Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age from two date string variables in YYYYMMDD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931071#M366305</link>
      <description>&lt;P&gt;So sorry for not providing complete information and thank you for responding. The solution that you have provided works for the test dataset that was created for this question. However, I am getting the following error in my original dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR 48-59: The format $YYMMDD was not found or could not be loaded.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please see the log below that has the similar kind of code.&lt;/P&gt;&lt;P&gt;264 data labcd4age /*labcd4anly labcd4_agelt13*/;&lt;BR /&gt;265 set lab_cd4anly1;&lt;BR /&gt;266 birth_dt=input(dob,yymmdd8.);&lt;BR /&gt;267 collectdt=input(sample_dt, yymmdd8.);&lt;BR /&gt;268 format birth_dt collectdt yymmdd8.;&lt;BR /&gt;269 age=yrdif(birth_dt, collectdt);&lt;/P&gt;&lt;P&gt;270 format dob collectdt yymmdd8.;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;--------&lt;BR /&gt;48&lt;BR /&gt;ERROR 48-59: The format $YYMMDD was not found or could not be loaded.&lt;/P&gt;&lt;P&gt;271 /*if age&amp;gt;=13 then output labcd4anly; else&lt;BR /&gt;272 output labcd4_agelt13;*/&lt;BR /&gt;273 run;&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;WARNING: The data set WORK.LABCD4AGE may be incomplete. When this step was stopped there were 0&lt;BR /&gt;observations and 15 variables.&lt;BR /&gt;WARNING: Data set WORK.LABCD4AGE was not replaced because this step was stopped.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please note these are the variable properties in the original dataset&lt;/P&gt;&lt;P&gt;Alphabetic List of Variables and Attributes&lt;/P&gt;&lt;P&gt;# Variable Type Len&amp;nbsp; &amp;nbsp;Format Informat Label&lt;/P&gt;&lt;P&gt;10 dob&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Char 8&amp;nbsp; &amp;nbsp; $8.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$8.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dob&lt;BR /&gt;3&amp;nbsp; sample_dt Char 8&amp;nbsp; &amp;nbsp; $8.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; $8.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; sample_dt&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2024 22:53:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931071#M366305</guid>
      <dc:creator>SASPreK</dc:creator>
      <dc:date>2024-06-05T22:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age from two date string variables in YYYYMMDD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931075#M366308</link>
      <description>&lt;PRE&gt;269 age=yrdif(birth_dt, collectdt);

270 format dob collectdt yymmdd8.;


--------
48
ERROR 48-59: The format $YYMMDD was not found or could not be loaded.&lt;/PRE&gt;
&lt;P&gt;The dollar sign in front of the YYMMDD means that at least one of the variables you attempted to format is character. Character variables cannot use numeric formats and this will happen when you try to assign a numeric format to a character variable. Looks like DOB is the culprit. Remove it from the Format statement or remove that entire Format statement if not needed.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2024 00:28:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931075#M366308</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-06-06T00:28:10Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age from two date string variables in YYYYMMDD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931077#M366310</link>
      <description>&lt;P&gt;You created the numeric variable BIRTH_DT from the character variable DOB.&lt;/P&gt;
&lt;PRE&gt;266 birth_dt=input(dob,yymmdd8.);&lt;/PRE&gt;
&lt;P&gt;But then tried to attach a numeric format to DOB.&lt;/P&gt;
&lt;PRE&gt;270 format dob collectdt yymmdd8.;
&lt;/PRE&gt;
&lt;P&gt;That should be BIRTH_DT in the format statement instead of DOB.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2024 01:42:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931077#M366310</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-06-06T01:42:05Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age from two date string variables in YYYYMMDD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931083#M366314</link>
      <description>&lt;P&gt;In the FORMAT statement, use birth_dt instead of dob. dob is character (as there is no NOTE about an automatic conversion when you use it in the INPUT function).&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2024 06:59:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931083#M366314</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-06-06T06:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age from two date string variables in YYYYMMDD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931267#M366387</link>
      <description>Thank you for catching that. I changed it to birth_dt and got the following error:&lt;BR /&gt;98 data labcd4age /*labcd4anly labcd4_agelt13*/;&lt;BR /&gt;99 set lab_cd4anly1;&lt;BR /&gt;100 birth_dt=input(dob,yymmdd8.);&lt;BR /&gt;101 collectdt=input(sample_dt, yymmdd8.);&lt;BR /&gt;102 format birth_dt collectdt yymmdd8.;&lt;BR /&gt;103 age=yrdif(birth_dt, collectdt);&lt;BR /&gt;104 format birth_dt collectdt yymmdd8.;&lt;BR /&gt;105 /*if age&amp;gt;=13 then output labcd4anly; else&lt;BR /&gt;106 output labcd4_agelt13;*/&lt;BR /&gt;107 run;&lt;BR /&gt;&lt;BR /&gt;NOTE: Invalid argument to function YRDIF(.,18431) at line 103 column 9.&lt;BR /&gt;</description>
      <pubDate>Fri, 07 Jun 2024 15:45:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931267#M366387</guid>
      <dc:creator>SASPreK</dc:creator>
      <dc:date>2024-06-07T15:45:15Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age from two date string variables in YYYYMMDD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931273#M366390</link>
      <description>&lt;P&gt;If there is no NOTE for invalid data, then the most likely cause is an empty dob variable. An empty string is a valid input and results in a missing value.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2024 21:31:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931273#M366390</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-06-07T21:31:00Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age from two date string variables in YYYYMMDD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931309#M366396</link>
      <description>&lt;P&gt;Thank you for the info. However, my dob variable does not seem to be empty in the dataset. Also, the log shows otherwise, see below the bold part.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).&lt;BR /&gt;100:15 100:20&lt;BR /&gt;NOTE: Invalid argument to function YRDIF(19650214,20100429) at line 100 column 9.&lt;BR /&gt;&lt;STRONG&gt;sample_dt=20100429 dob=19650214&lt;/STRONG&gt; age=. _ERROR_=1 _N_=1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please see this was another note&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: Mathematical operations could not be performed at the following places. The results of the&lt;BR /&gt;operations have been set to missing values.&lt;BR /&gt;Each place is given by: (Number of times) at (Line):(Column).&lt;BR /&gt;7272426 at 100:9&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2024 17:42:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931309#M366396</guid>
      <dc:creator>SASPreK</dc:creator>
      <dc:date>2024-06-07T17:42:28Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age from two date string variables in YYYYMMDD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931312#M366398</link>
      <description>&lt;P&gt;I removed the formats and ran the following code&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data labcd4age /*labcd4anly labcd4_agelt13*/;&lt;BR /&gt;set lab_cd4anly1;&lt;BR /&gt;age=yrdif(dob, sample_dt);&lt;BR /&gt;/*if age&amp;gt;=13 then output labcd4anly; else&lt;BR /&gt;output labcd4_agelt13;*/&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And got the following error&lt;/P&gt;&lt;P&gt;NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).&lt;BR /&gt;100:15 100:20&lt;BR /&gt;NOTE: Invalid argument to function YRDIF(19650214,20100429) at line 100 column 9.&lt;BR /&gt;sample_dt=20100429 dob=19650214 age=. _ERROR_=1 _N_=1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: Mathematical operations could not be performed at the following places. The results of the&lt;BR /&gt;operations have been set to missing values.&lt;BR /&gt;Each place is given by: (Number of times) at (Line):(Column).&lt;BR /&gt;7272426 at 100:9&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2024 17:45:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931312#M366398</guid>
      <dc:creator>SASPreK</dc:creator>
      <dc:date>2024-06-07T17:45:39Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age from two date string variables in YYYYMMDD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931343#M366405</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466295"&gt;@SASPreK&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you for the info. However, my dob variable does not seem to be empty in the dataset. Also, the log shows otherwise, see below the bold part.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).&lt;BR /&gt;100:15 100:20&lt;BR /&gt;NOTE: Invalid argument to function YRDIF(19650214,20100429) at line 100 column 9.&lt;BR /&gt;&lt;STRONG&gt;sample_dt=20100429 dob=19650214&lt;/STRONG&gt; age=. _ERROR_=1 _N_=1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please see this was another note&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: Mathematical operations could not be performed at the following places. The results of the&lt;BR /&gt;operations have been set to missing values.&lt;BR /&gt;Each place is given by: (Number of times) at (Line):(Column).&lt;BR /&gt;7272426 at 100:9&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your arguments to the YRDIF function are not valid SAS dates. SAS dates are counts of days, with 1960-01-01 as day zero.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2024 21:35:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931343#M366405</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-06-07T21:35:12Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age from two date string variables in YYYYMMDD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931351#M366409</link>
      <description>&lt;P&gt;It is going to be hard to help you if you don't provide complete information.&lt;/P&gt;
&lt;P&gt;What is the code on line 100 that is using character expressions where numeric expressions are needed?&amp;nbsp; Does it have anything to do with the two variables whose values you show?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If SAMPLE_DT and DOB are character variables then they are definitely not DATE values since DATE values are numbers.&amp;nbsp; &amp;nbsp;If you tried to use them as if they were dates you would get that message about converting character strings to numbers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if they are numeric variables then they are also definitely not date values (unless you decided to confuse the poor humans that have to look at the date values by attaching the YYMMDDN8. format to them so they print as just a string of digits without any separator characters between the year month and day of the month parts).&amp;nbsp; A date value is going to be in the 20K range not the 20M range. So number like 20,100,429. might look to a human like it is intended to be interpreted as yy,yym,mdd date digits.&amp;nbsp; But SAS won't think that..&amp;nbsp; The number SAS uses to store April 29, 2010 is the number&amp;nbsp;18,381.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2024 22:04:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931351#M366409</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-06-07T22:04:21Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age from two date string variables in YYYYMMDD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931609#M366485</link>
      <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466295"&gt;@SASPreK&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;This is my humble opinion to your question based on your initial post.&lt;BR /&gt;(Often SAS provides many ways of doing the same thing. I am showing how I would do it.)&lt;BR /&gt;You need to tell SAS that you are reading date values and their format by using&amp;nbsp; the informat statement.&lt;/P&gt;
&lt;P&gt;This was not done in your code.&lt;BR /&gt;Optionally tell SAS how to store the date values by using the format statement.&lt;/P&gt;
&lt;P&gt;Once done the age can be calculated. Add 'AGE" option to yrdiff&amp;nbsp; function to tell that you are calculating age.&amp;nbsp; Look &lt;A href="https://documentation.sas.com/doc/en/vdmmlcdc/8.1/lefunctionsref/p1pmmr2dtec32an1vbsqmm3abil5.htm" target="_self"&gt;here&lt;/A&gt; for details on yrdiff.&lt;BR /&gt;Your updated code will be as follows&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	informat dob sample_dt yymmdd8.;&lt;BR /&gt;    format dob sample_dt yymmddn8.;
	input dob sample_dt;
	age=yrdif(dob, sample_dt, 'AGE');
	datalines;
19650214    20100429
19800724    20210823
19991208    20090908
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The output will be as follows&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sajid01_0-1718047565759.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/97194iFC3D9C0DC6198E09/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sajid01_0-1718047565759.png" alt="Sajid01_0-1718047565759.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jun 2024 19:29:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931609#M366485</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2024-06-10T19:29:08Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age from two date string variables in YYYYMMDD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931621#M366490</link>
      <description>&lt;P&gt;The largest number that SAS will treat as a date currently is 6589335 which corresponds to 31DEC20000 (yes 5 zeroes or rounghly 18,000 years in the future.&lt;/P&gt;
&lt;P&gt;When you call function that expects to use numeric values with a character value like '19650214' or '20100429' then SAS applies internal rules to convert the characters to numbers (that is the conversion message you see).&lt;/P&gt;
&lt;P&gt;So '19650214' becomes the number 19650214. Which is 13060879 larger than the largest allowable date. So the YRDIF, and YEAR, MONTH, DAY, INTNX, INTCK, HOLIDAY and any other date related function will fail.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is your responsibility to convert character values to dates using a proper informat for the type of value you currently have.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/466295"&gt;@SASPreK&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you for the info. However, my dob variable does not seem to be empty in the dataset. Also, the log shows otherwise, see below the bold part.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).&lt;BR /&gt;100:15 100:20&lt;BR /&gt;NOTE: Invalid argument to function YRDIF(19650214,20100429) at line 100 column 9.&lt;BR /&gt;&lt;STRONG&gt;sample_dt=20100429 dob=19650214&lt;/STRONG&gt; age=. _ERROR_=1 _N_=1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please see this was another note&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: Mathematical operations could not be performed at the following places. The results of the&lt;BR /&gt;operations have been set to missing values.&lt;BR /&gt;Each place is given by: (Number of times) at (Line):(Column).&lt;BR /&gt;7272426 at 100:9&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jun 2024 20:08:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931621#M366490</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-06-10T20:08:05Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age from two date string variables in YYYYMMDD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931629#M366494</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/131732"&gt;@Sajid01&lt;/a&gt;&amp;nbsp;Two quick corrections.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You said:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;You need to tell SAS that you are reading date values and their format by using&amp;nbsp; the informat statement.&lt;/P&gt;
&lt;P&gt;This was not done in your code.&lt;BR /&gt;Optionally tell SAS how to store the date values by using the format statement.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You need to tell SAS &lt;STRONG&gt;how to read&lt;/STRONG&gt; the date values by &lt;STRONG&gt;either&lt;/STRONG&gt; attaching an informat to the variable with an INFORMAT statement or specifying an informat in the INPUT statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can tell SAS &lt;STRONG&gt;how to display&lt;/STRONG&gt; the date value by attaching a format to the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The TYPE of the variable (SAS only has two variable types: fixed length character strings and floating point numbers) is what determines how SAS stores the values.&amp;nbsp; The INFORMAT and FORMAT are used for converting the values from or to text strings.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you picture seems to show DOB as character, since the name is left aligned above the column.&amp;nbsp; When I run your data step the resulting dataset prints like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1718051534058.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/97198iB3A1457898E55DFC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1718051534058.png" alt="Tom_0-1718051534058.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Notice how all three variables have the column header and values right aligned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jun 2024 20:33:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931629#M366494</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-06-10T20:33:21Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating age from two date string variables in YYYYMMDD</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931997#M366650</link>
      <description>&lt;P&gt;Thank&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/131732"&gt;@Sajid01&lt;/a&gt;&amp;nbsp; for all your very helpful comments.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With the help of your comments and carefully looking at the error messages and variable attributes I realized my data was in this format.&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input dob $ sample_dt $ ;&lt;BR /&gt;&lt;STRONG&gt;format dob sample_dt 8.;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;informat dob sample_dt 8.;&lt;/STRONG&gt;&lt;BR /&gt;datalines;&lt;BR /&gt;19650214 20100429&lt;BR /&gt;19800724 20210823&lt;BR /&gt;19991208 20090908&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My date variables were not in date format as pointed out by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;but my variables were not being converted to date variable by using any format and informat of yymmdd8. functions because it had it's own format and informat of 8. So, I checked the sas community and used the solution provided by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;to this thread&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-Character-to-Date/td-p/742951?lightbox-message-images-743004=59673iAFF420B5BA5A58D5" target="_blank"&gt;https://communities.sas.com/t5/SAS-Enterprise-Guide/Convert-Character-to-Date/td-p/742951?lightbox-message-images-743004=59673iAFF420B5BA5A58D5&lt;/A&gt;&amp;nbsp;However, my actual dataset was not completely clean and was still giving me some errors at specific rows and columns because the date values had some special characters or missing values. After following the two steps of converting to date and cleaning my dataset, I was finally able to get the output I had wanted. Thank you all once again &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jun 2024 19:00:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-age-from-two-date-string-variables-in-YYYYMMDD/m-p/931997#M366650</guid>
      <dc:creator>SASPreK</dc:creator>
      <dc:date>2024-06-12T19:00:29Z</dc:date>
    </item>
  </channel>
</rss>

