<?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: Lesson 4 creating new columns practice p104p04.sas in Programming 1 and 2</title>
    <link>https://communities.sas.com/t5/Programming-1-and-2/Lesson-4-creating-new-columns-practice-p104p04-sas/m-p/527571#M175</link>
    <description>&lt;P&gt;A format takes the form:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;formatNameW.d&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;formatName is the formatName, ie comma&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;W is the width of the variable that tells SAS how many digits or character to show&lt;/P&gt;
&lt;P&gt;d is decimal portion, and how many decimals to show.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that if you have a width of 10 and d=3 that the decimal is actually 4 spaces, so you have&lt;/P&gt;
&lt;P&gt;F10.3 that means you have a number of the form&amp;nbsp;######.###&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is all documented here&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm#n134ahpcz8murvn1x7went6p2czo.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm#n134ahpcz8murvn1x7went6p2czo.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS. Instead of using colour to highlight your code please consider using the code blocks (7th icon in editor) which ensures your code is posted correctly.&amp;nbsp;&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/254067"&gt;@melissagodfrey&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;FONT color="#008000"&gt;Instructions in Green&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000"&gt;***********************************************************;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* LESSON 4, PRACTICE 4 *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* a) Create a new column named SqMiles by multiplying *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* Acres by .0015625. *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* b) Create a new column named Camping as the sum of *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* OtherCamping, TentCampers, RVCampers, and *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* BackcountryCampers. *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* c) Format SqMiles and Camping to include commas and *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* zero decimal places. *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* d) Modify the KEEP statement to include the new *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* columns. Run the program. *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;***********************************************************;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF00FF"&gt;My answer in Pink:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF00FF"&gt;data np_summary_update;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;set pg1.np_summary;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;keep Reg ParkName DayVisits OtherLodging Acres SqMiles Camping; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;*Add assignment statements;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;SqMiles=Acres*.0015625;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;Camping=sum(OtherCamping, TentCampers, RVCampers, BackcountryCampers);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;format SqMiles Camping comma.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF00FF"&gt;What is the difference between&amp;nbsp;&lt;SPAN&gt;format SqMiles Camping comma.&amp;nbsp; &amp;nbsp; &amp;nbsp;and the solution format below?&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF00FF"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;STRONG&gt;format SqMiles comma6. Camping comma10.; &lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT color="#FF00FF"&gt;It appears comma. is more flexible as it will simply add commas to the number and the .&amp;nbsp;with no number after it assures no decimals. Why would you need to specify the number of digits ex comma6.&amp;nbsp; &amp;nbsp; ?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF00FF"&gt;Thanks!&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 16 Jan 2019 00:21:24 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-01-16T00:21:24Z</dc:date>
    <item>
      <title>Lesson 4 creating new columns practice p104p04.sas</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Lesson-4-creating-new-columns-practice-p104p04-sas/m-p/527531#M174</link>
      <description>&lt;P&gt;&lt;FONT color="#008000"&gt;Instructions in Green&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#008000"&gt;***********************************************************;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* LESSON 4, PRACTICE 4 *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* a) Create a new column named SqMiles by multiplying *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* Acres by .0015625. *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* b) Create a new column named Camping as the sum of *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* OtherCamping, TentCampers, RVCampers, and *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* BackcountryCampers. *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* c) Format SqMiles and Camping to include commas and *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* zero decimal places. *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* d) Modify the KEEP statement to include the new *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* columns. Run the program. *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;***********************************************************;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF00FF"&gt;My answer in Pink:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF00FF"&gt;data np_summary_update;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;set pg1.np_summary;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;keep Reg ParkName DayVisits OtherLodging Acres SqMiles Camping; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;*Add assignment statements;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;SqMiles=Acres*.0015625;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;Camping=sum(OtherCamping, TentCampers, RVCampers, BackcountryCampers);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;format SqMiles Camping comma.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF00FF"&gt;What is the difference between&amp;nbsp;&lt;SPAN&gt;format SqMiles Camping comma.&amp;nbsp; &amp;nbsp; &amp;nbsp;and the solution format below?&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF00FF"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;format SqMiles comma6. Camping comma10.; &lt;/STRONG&gt;&lt;/PRE&gt;&lt;P&gt;&lt;FONT color="#FF00FF"&gt;It appears comma. is more flexible as it will simply add commas to the number and the .&amp;nbsp;with no number after it assures no decimals. Why would you need to specify the number of digits ex comma6.&amp;nbsp; &amp;nbsp; ?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF00FF"&gt;Thanks!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 21:40:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Lesson-4-creating-new-columns-practice-p104p04-sas/m-p/527531#M174</guid>
      <dc:creator>melissagodfrey</dc:creator>
      <dc:date>2019-01-15T21:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: Lesson 4 creating new columns practice p104p04.sas</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Lesson-4-creating-new-columns-practice-p104p04-sas/m-p/527571#M175</link>
      <description>&lt;P&gt;A format takes the form:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;formatNameW.d&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;formatName is the formatName, ie comma&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;W is the width of the variable that tells SAS how many digits or character to show&lt;/P&gt;
&lt;P&gt;d is decimal portion, and how many decimals to show.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that if you have a width of 10 and d=3 that the decimal is actually 4 spaces, so you have&lt;/P&gt;
&lt;P&gt;F10.3 that means you have a number of the form&amp;nbsp;######.###&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is all documented here&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm#n134ahpcz8murvn1x7went6p2czo.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/leforinforref/64790/HTML/default/viewer.htm#n134ahpcz8murvn1x7went6p2czo.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS. Instead of using colour to highlight your code please consider using the code blocks (7th icon in editor) which ensures your code is posted correctly.&amp;nbsp;&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/254067"&gt;@melissagodfrey&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;FONT color="#008000"&gt;Instructions in Green&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#008000"&gt;***********************************************************;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* LESSON 4, PRACTICE 4 *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* a) Create a new column named SqMiles by multiplying *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* Acres by .0015625. *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* b) Create a new column named Camping as the sum of *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* OtherCamping, TentCampers, RVCampers, and *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* BackcountryCampers. *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* c) Format SqMiles and Camping to include commas and *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* zero decimal places. *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* d) Modify the KEEP statement to include the new *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;* columns. Run the program. *;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#008000"&gt;***********************************************************;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF00FF"&gt;My answer in Pink:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF00FF"&gt;data np_summary_update;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;set pg1.np_summary;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;keep Reg ParkName DayVisits OtherLodging Acres SqMiles Camping; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;*Add assignment statements;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;SqMiles=Acres*.0015625;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;Camping=sum(OtherCamping, TentCampers, RVCampers, BackcountryCampers);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;format SqMiles Camping comma.&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF00FF"&gt;run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF00FF"&gt;What is the difference between&amp;nbsp;&lt;SPAN&gt;format SqMiles Camping comma.&amp;nbsp; &amp;nbsp; &amp;nbsp;and the solution format below?&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF00FF"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;STRONG&gt;format SqMiles comma6. Camping comma10.; &lt;/STRONG&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;FONT color="#FF00FF"&gt;It appears comma. is more flexible as it will simply add commas to the number and the .&amp;nbsp;with no number after it assures no decimals. Why would you need to specify the number of digits ex comma6.&amp;nbsp; &amp;nbsp; ?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF00FF"&gt;Thanks!&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 00:21:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Lesson-4-creating-new-columns-practice-p104p04-sas/m-p/527571#M175</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-16T00:21:24Z</dc:date>
    </item>
    <item>
      <title>Re: Lesson 4 creating new columns practice p104p04.sas</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Lesson-4-creating-new-columns-practice-p104p04-sas/m-p/527574#M176</link>
      <description>&lt;P&gt;If you read the documentation for the COMMAw.d format it has an important section regarding W:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;H4 class="xis-argument"&gt;&lt;SPAN class="xis-userSuppliedValue"&gt;w&lt;/SPAN&gt;&lt;/H4&gt;
&lt;DIV class="xis-argumentDescription"&gt;
&lt;P class="xis-paraSimpleFirst"&gt;specifies the width of the output field.&lt;/P&gt;
&lt;TABLE class="xis-summary"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="xis-summaryDefault"&gt;Default&lt;/TD&gt;
&lt;TD class="xis-summaryText"&gt;6&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which means that if you do not specify a W value that the format will attempt to display the value in only 6 characters, ie COMMA6.&lt;/P&gt;
&lt;P&gt;When you use Comma10. then it allows for more characters in display.&lt;/P&gt;
&lt;P&gt;You need to always consider what you want to display for output. If you want decimals and the value is large enough if your width, or W, is not large enough to include the digits before the decimal, the commas (or parantheses, % sign or what have you ) and the decimal itself then the result will get truncated.&lt;/P&gt;
&lt;P&gt;Consider this code (look in the log for the result):&lt;/P&gt;
&lt;PRE&gt;data _null_;
   x=123456789.45678;
   put x=comma6. x=comma10. x=f13.5 x=f15.5 x=comma15.5 x=comma19.5;
run;&lt;/PRE&gt;
&lt;P&gt;The result shows the same value displayed with a number of formats. You might find the 1st and&amp;nbsp;5th very interesting as SAS takes alternate approaches to "best fitting" the displayed value to your request. Also see the note about format too small.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Remember also then when you have a list of variables that the first defined format is applied to all of the preceding variables.&lt;/P&gt;
&lt;P&gt;Every format has a default length and sometimes you may find funny results such as 2E3 instead of an expected 2019 because the format has been set to BEST3. Which reduces the number of spaces allowed so SAS goes to scientific notation.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 00:25:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Lesson-4-creating-new-columns-practice-p104p04-sas/m-p/527574#M176</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-01-16T00:25:30Z</dc:date>
    </item>
    <item>
      <title>Re: Lesson 4 creating new columns practice p104p04.sas</title>
      <link>https://communities.sas.com/t5/Programming-1-and-2/Lesson-4-creating-new-columns-practice-p104p04-sas/m-p/527586#M177</link>
      <description>&lt;P&gt;wonderful thank you that was exactly the answer i was looking for, it makes sense that the default is 6 digits, now i understand why they allow you to specify. thanks a bunch!&lt;/P&gt;</description>
      <pubDate>Wed, 16 Jan 2019 01:18:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Programming-1-and-2/Lesson-4-creating-new-columns-practice-p104p04-sas/m-p/527586#M177</guid>
      <dc:creator>melissagodfrey</dc:creator>
      <dc:date>2019-01-16T01:18:56Z</dc:date>
    </item>
  </channel>
</rss>

