<?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: Query on Lesson 4 - Computing new Columns - Practice level 2 in Programming 1 and 2</title>
    <link>https://communities.sas.com/t5/Programming-1-and-2/Query-on-Lesson-4-Computing-new-Columns-Practice-level-2/m-p/824629#M1135</link>
    <description>Many thanks for your clear explanation &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
    <pubDate>Thu, 21 Jul 2022 13:11:43 GMT</pubDate>
    <dc:creator>mk133201</dc:creator>
    <dc:date>2022-07-21T13:11:43Z</dc:date>
    <item>
      <title>Query on Lesson 4 - Computing new Columns - Practice level 2</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Query-on-Lesson-4-Computing-new-Columns-Practice-level-2/m-p/824561#M1133</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am reading through the solution for Level 2 Practice in Lesson 4 Creating New Columns with Character and Date Functions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the original file, pg1.eu_occ, the type for "YearMon" is character. Hence after substring the Year and Month, should they be character type too?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But does it not need to be in numeric format for the MDY function to work?&amp;nbsp; Can anyone please help on this, thank you so much!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data eu_occ_total;
    set pg1.eu_occ;
    Year=substr(YearMon,1,4);
    Month=substr(YearMon,6,2);
    ReportDate=MDY(Month,1,Year);
    Total=sum(Hotel,ShortStay,Camp);
    format Hotel ShortStay Camp Total comma17.
           ReportDate monyy7.;
    keep Country Hotel ShortStay Camp ReportDate Total;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2022 08:13:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Query-on-Lesson-4-Computing-new-Columns-Practice-level-2/m-p/824561#M1133</guid>
      <dc:creator>mk133201</dc:creator>
      <dc:date>2022-07-21T08:13:13Z</dc:date>
    </item>
    <item>
      <title>Re: Query on Lesson 4 - Computing new Columns - Practice level 2</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Query-on-Lesson-4-Computing-new-Columns-Practice-level-2/m-p/824570#M1134</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/395244"&gt;@mk133201&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are right. The SUBSTR function returns character values and the MDY function expects numeric arguments. Therefore, these three lines of code are inconsistent:&lt;/P&gt;
&lt;PRE&gt;    Year=substr(YearMon,1,4);
    Month=substr(YearMon,6,2);
    ReportDate=MDY(Month,1,Year);&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code will work nevertheless because of automatic type conversion: Character arguments of the MDY function containing suitable digit strings like &lt;FONT face="courier new,courier"&gt;"2017"&lt;/FONT&gt; for &lt;FONT face="courier new,courier"&gt;Year&lt;/FONT&gt; would be converted to the corresponding numeric values. &lt;EM&gt;But this is bad practice&lt;/EM&gt; because it would cause a note in the log saying&lt;/P&gt;
&lt;PRE&gt;NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
...&lt;/PRE&gt;
&lt;P&gt;which should be avoided. The same type of note would be written to the log if &lt;FONT face="courier new,courier"&gt;Year&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;Month&lt;/FONT&gt; were numeric variables in dataset&amp;nbsp;&lt;FONT face="courier new,courier"&gt;pg1.eu_occ&lt;/FONT&gt;, as the automatic character-to-numeric conversion would then occur in the two assignment statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A clean solution would convert the substrings explicitly by means of the INPUT function, e.g.:&lt;/P&gt;
&lt;PRE&gt;Year =&lt;STRONG&gt;input(&lt;/STRONG&gt;substr(YearMon,1,4)&lt;STRONG&gt;,32.);&lt;/STRONG&gt;
Month=&lt;STRONG&gt;input(&lt;/STRONG&gt;substr(YearMon,6,2)&lt;STRONG&gt;,32.);&lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;(The informat lengths, here: 32, could also be chosen as 4 and 2, resp.)&lt;/P&gt;</description>
      <pubDate>Thu, 21 Jul 2022 09:10:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Query-on-Lesson-4-Computing-new-Columns-Practice-level-2/m-p/824570#M1134</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-07-21T09:10:14Z</dc:date>
    </item>
    <item>
      <title>Re: Query on Lesson 4 - Computing new Columns - Practice level 2</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Query-on-Lesson-4-Computing-new-Columns-Practice-level-2/m-p/824629#M1135</link>
      <description>Many thanks for your clear explanation &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Thu, 21 Jul 2022 13:11:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Query-on-Lesson-4-Computing-new-Columns-Practice-level-2/m-p/824629#M1135</guid>
      <dc:creator>mk133201</dc:creator>
      <dc:date>2022-07-21T13:11:43Z</dc:date>
    </item>
  </channel>
</rss>

