<?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 use SUBSTR() function to create date variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/use-SUBSTR-function-to-create-date-variables/m-p/693488#M211458</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Attached is the "president.txt" file.&lt;/P&gt;&lt;P&gt;The question asked me to use substr() function to create a new character variables to hold the day, month, and year from variable DOBC.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the function but it didn't work.&lt;/P&gt;&lt;P&gt;Could anyone help me to correct the code? Thanks a lot.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename TXTfile '/folders/myfolders/Assignment 2/President.txt';
data President;
 infile TXTfile expandtabs lrecl=300 truncover;
 input @1 FullName $22. 
       @25 City $19. 
       @49 State &amp;amp; $20. 
       ASP :2. 
       DOB :mmddyy10. 
       Term :4. 
       Votes :comma10. 
       PercVote :percent10.2 
       ;
 DOBC = DOB;
 DOBC2 = DOB;
 format DOB mmddyy10. Votes comma10. PercVote percent10.2 
        DOBC date9. DOBC2 ddmmyy10.;
run;

data test;
 set President;
 length day $2 mon $3 year $4;
 
 day = substr(DOBC,1,2);
 mon = substr(DOBC,3,3);
 year = substr(DOBC,6);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 22 Oct 2020 12:45:45 GMT</pubDate>
    <dc:creator>KyuL</dc:creator>
    <dc:date>2020-10-22T12:45:45Z</dc:date>
    <item>
      <title>use SUBSTR() function to create date variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-SUBSTR-function-to-create-date-variables/m-p/693488#M211458</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Attached is the "president.txt" file.&lt;/P&gt;&lt;P&gt;The question asked me to use substr() function to create a new character variables to hold the day, month, and year from variable DOBC.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the function but it didn't work.&lt;/P&gt;&lt;P&gt;Could anyone help me to correct the code? Thanks a lot.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename TXTfile '/folders/myfolders/Assignment 2/President.txt';
data President;
 infile TXTfile expandtabs lrecl=300 truncover;
 input @1 FullName $22. 
       @25 City $19. 
       @49 State &amp;amp; $20. 
       ASP :2. 
       DOB :mmddyy10. 
       Term :4. 
       Votes :comma10. 
       PercVote :percent10.2 
       ;
 DOBC = DOB;
 DOBC2 = DOB;
 format DOB mmddyy10. Votes comma10. PercVote percent10.2 
        DOBC date9. DOBC2 ddmmyy10.;
run;

data test;
 set President;
 length day $2 mon $3 year $4;
 
 day = substr(DOBC,1,2);
 mon = substr(DOBC,3,3);
 year = substr(DOBC,6);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Oct 2020 12:45:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-SUBSTR-function-to-create-date-variables/m-p/693488#M211458</guid>
      <dc:creator>KyuL</dc:creator>
      <dc:date>2020-10-22T12:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: use SUBSTR() function to create date variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-SUBSTR-function-to-create-date-variables/m-p/693492#M211462</link>
      <description>&lt;P&gt;SUBSTR is a character function, dates are numbers (count of days from 1960-01-01) and stored in numeric variables.&lt;/P&gt;
&lt;P&gt;The question makes therefore no sense in a SAS context.&lt;/P&gt;
&lt;P&gt;For dates, you use the DAY, MONTH and YEAR functions to extract those&amp;nbsp;&lt;EM&gt;numeric&lt;/EM&gt; values from a date.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2020 13:01:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-SUBSTR-function-to-create-date-variables/m-p/693492#M211462</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-22T13:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: use SUBSTR() function to create date variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-SUBSTR-function-to-create-date-variables/m-p/693493#M211463</link>
      <description>&lt;P&gt;SUBSTR() works on character variables. You defined DOBC as a numeric variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you give SUBSTR() a number it will first convert the number into a character string using the BEST12. format.&amp;nbsp; This will cause two problems with your code.&amp;nbsp; First dates are represented as number of days since 1960, so there are no digits that will look like month or year number.&amp;nbsp; Second is the values will have leading spaces since the number for today is 22,210 which only needs 5 digits, not 12.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2020 13:02:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-SUBSTR-function-to-create-date-variables/m-p/693493#M211463</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-10-22T13:02:55Z</dc:date>
    </item>
    <item>
      <title>Re: use SUBSTR() function to create date variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-SUBSTR-function-to-create-date-variables/m-p/693500#M211468</link>
      <description>&lt;P&gt;Thanks for the explanation. I converted DOBC to&amp;nbsp;&lt;SPAN style="font-family: inherit;"&gt;character variable now the substr() works.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2020 13:17:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-SUBSTR-function-to-create-date-variables/m-p/693500#M211468</guid>
      <dc:creator>KyuL</dc:creator>
      <dc:date>2020-10-22T13:17:15Z</dc:date>
    </item>
    <item>
      <title>Re: use SUBSTR() function to create date variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/use-SUBSTR-function-to-create-date-variables/m-p/693501#M211469</link>
      <description>&lt;P&gt;Thank you for the explanation.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Oct 2020 13:17:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/use-SUBSTR-function-to-create-date-variables/m-p/693501#M211469</guid>
      <dc:creator>KyuL</dc:creator>
      <dc:date>2020-10-22T13:17:48Z</dc:date>
    </item>
  </channel>
</rss>

