<?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: Can't Convert Num to Char and Add Leading Zeros in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Can-t-Convert-Num-to-Char-and-Add-Leading-Zeros/m-p/733992#M28607</link>
    <description>&lt;P&gt;OH gosh! That's embarrassing! Thank you for catching that. I guess I have been staring too long--should have walked away and come back.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 14 Apr 2021 23:05:35 GMT</pubDate>
    <dc:creator>raivester</dc:creator>
    <dc:date>2021-04-14T23:05:35Z</dc:date>
    <item>
      <title>Can't Convert Num to Char and Add Leading Zeros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-t-Convert-Num-to-Char-and-Add-Leading-Zeros/m-p/733987#M28605</link>
      <description>&lt;P&gt;I am attempting to take the number of days between a start date (January 1, 2019) and an end date (January 1, 2019 + some length of time) and calculate and concatenate the two-digit number of years, months, and days. For example, a time period of 440 days is 1 year, 2 months and 15 days--the resultant number I would expect to get in the "duration" variable would be: 010215. I attempt this by running the following, but the month variable does not convert to character. Any ideas?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data out;
  set in;
  	length duration $6

	** create an end date variable to calculate years, days, and months between Jan 1 2019 and end date based on total days;
	date_end = "1JAN2019"d+total_days;

	yr    = put(intck('year',"1JAN2019"d,date_end,'c'), z2.);
	mntha = intck('month',intnx('year',"1JAN2019"d,yr,'s'),date_end,'c');
	daya  = date_end - intnx('month',"1JAN2019"d,mnth+yr*12,'s');
&lt;BR /&gt;        *Since I perform this operation below, I had to keep the temp month and day variables&lt;BR /&gt;         numeric--I will change them to character with leading zeros after. Since I do not use&lt;BR /&gt;         the year variable here, I converted this to char with leading zeros in the variable's&lt;BR /&gt;         creation, above.;
	if daya=30 then do;
		mntha+1;
		daya=0;
	end;

	mnth = put(mntha, z2.);
	day  = put(daya, z2.);
	
	duration=cats(yr,mnth,day);

run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 14 Apr 2021 22:23:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-t-Convert-Num-to-Char-and-Add-Leading-Zeros/m-p/733987#M28605</guid>
      <dc:creator>raivester</dc:creator>
      <dc:date>2021-04-14T22:23:12Z</dc:date>
    </item>
    <item>
      <title>Re: Can't Convert Num to Char and Add Leading Zeros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-t-Convert-Num-to-Char-and-Add-Leading-Zeros/m-p/733990#M28606</link>
      <description>daya  = date_end - intnx('month',"1JAN2019"d,mnth+yr*12,'s');&lt;BR /&gt;&lt;BR /&gt;Should that mth  be mntha?&lt;BR /&gt;Or does that mnth exist in data set already?</description>
      <pubDate>Wed, 14 Apr 2021 22:35:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-t-Convert-Num-to-Char-and-Add-Leading-Zeros/m-p/733990#M28606</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-14T22:35:42Z</dc:date>
    </item>
    <item>
      <title>Re: Can't Convert Num to Char and Add Leading Zeros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-t-Convert-Num-to-Char-and-Add-Leading-Zeros/m-p/733992#M28607</link>
      <description>&lt;P&gt;OH gosh! That's embarrassing! Thank you for catching that. I guess I have been staring too long--should have walked away and come back.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Apr 2021 23:05:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-t-Convert-Num-to-Char-and-Add-Leading-Zeros/m-p/733992#M28607</guid>
      <dc:creator>raivester</dc:creator>
      <dc:date>2021-04-14T23:05:35Z</dc:date>
    </item>
  </channel>
</rss>

