<?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: Question in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Question/m-p/528652#M144321</link>
    <description>Thanks for the code! I was hoping that there was a number format in sas&lt;BR /&gt;that stored either years or months or weeks or combinations. This is&lt;BR /&gt;very helpful!&lt;BR /&gt;</description>
    <pubDate>Sun, 20 Jan 2019 23:06:15 GMT</pubDate>
    <dc:creator>Ariel_1</dc:creator>
    <dc:date>2019-01-20T23:06:15Z</dc:date>
    <item>
      <title>Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question/m-p/528640#M144316</link>
      <description>&lt;P&gt;I have a SAS data set file.&amp;nbsp; One of my columns is an age column that has the age of the subject either as the age in months, weeks, years, or years and month (or missing, which I am treating as years).&amp;nbsp; Is there a SAS format that will help me store the data (in a new column obviously) as a numeric field.&amp;nbsp; I'd like all of the data to show me in years.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Jan 2019 20:46:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question/m-p/528640#M144316</guid>
      <dc:creator>Ariel_1</dc:creator>
      <dc:date>2019-01-20T20:46:54Z</dc:date>
    </item>
    <item>
      <title>Re: Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question/m-p/528642#M144317</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hello and welcome to the SAS communities &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you show us what your data looks like? Is there an identifier of whether the age is represented as months , years or years and month?&lt;/P&gt;</description>
      <pubDate>Sun, 20 Jan 2019 21:33:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question/m-p/528642#M144317</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-20T21:33:46Z</dc:date>
    </item>
    <item>
      <title>Re: Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question/m-p/528643#M144318</link>
      <description>&lt;P&gt;Its a text field - here's an example of what the data looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;17 Years&lt;/P&gt;&lt;P&gt;5 Weeks&lt;/P&gt;&lt;P&gt;7&lt;/P&gt;&lt;P&gt;5 Years 4 Months&lt;/P&gt;&lt;P&gt;3 Months&lt;/P&gt;</description>
      <pubDate>Sun, 20 Jan 2019 21:40:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question/m-p/528643#M144318</guid>
      <dc:creator>Ariel_1</dc:creator>
      <dc:date>2019-01-20T21:40:10Z</dc:date>
    </item>
    <item>
      <title>Re: Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question/m-p/528645#M144319</link>
      <description>&lt;P&gt;There are several ways to do this. Is it a requirement to use a format? I do not think there is a standard format available&lt;/P&gt;</description>
      <pubDate>Sun, 20 Jan 2019 21:49:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question/m-p/528645#M144319</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-20T21:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question/m-p/528646#M144320</link>
      <description>&lt;P&gt;There is definitely a more efficient way, but here is an approach that works&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input string:$20.;
infile datalines dlm=',';
datalines;
17 Years
5 Weeks
7
5 Years 4 Months
3 Months
;

data want(drop=_: i);
   set have;
   if (findw(string, 'Years')&amp;gt;0 &amp;amp; countw(string)=2) | anyalpha(string)=0 then do;
      age=input(compress(string, , 'kd'), 8.);
   end;
   else do;
      do i=1 to countw(string);
         if anyalpha(scan(string, i))=0 then do;
            if scan(string, i+1)='Years' then do;
               _ageY=input(scan(string, i), 8.);
            end;
            if scan(string, i+1)='Months' then do;
               _ageM=input(scan(string, i), 8.)/12;
            end;
            if scan(string, i+1)='Weeks' then do;
               _ageW=input(scan(string, i), 8.)/52.177457;
            end;
         end;
      end;
      age=sum(_ageY, _ageM, _ageW);
   end;

   format age 8.2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 20 Jan 2019 22:22:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question/m-p/528646#M144320</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-20T22:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question/m-p/528652#M144321</link>
      <description>Thanks for the code! I was hoping that there was a number format in sas&lt;BR /&gt;that stored either years or months or weeks or combinations. This is&lt;BR /&gt;very helpful!&lt;BR /&gt;</description>
      <pubDate>Sun, 20 Jan 2019 23:06:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question/m-p/528652#M144321</guid>
      <dc:creator>Ariel_1</dc:creator>
      <dc:date>2019-01-20T23:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: Question</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Question/m-p/528705#M144336</link>
      <description>&lt;P&gt;I doubt that a format already exists. It may be possible to write an appropriate format, but the code will not be pretty either.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Jan 2019 09:32:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Question/m-p/528705#M144336</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-21T09:32:44Z</dc:date>
    </item>
  </channel>
</rss>

