<?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: what is the usage of PROC FORMAT in the codes? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-usage-of-PROC-FORMAT-in-the-codes/m-p/234999#M43016</link>
    <description>the example is from "the little SAS book", at page 231, which is an very classical SAS book, so I suppose it should not make mistake. I comfirm that the codes are all from the book and  "$AgeGp" is not misspell, that is what makes me confused</description>
    <pubDate>Tue, 17 Nov 2015 13:35:22 GMT</pubDate>
    <dc:creator>DingDing</dc:creator>
    <dc:date>2015-11-17T13:35:22Z</dc:date>
    <item>
      <title>what is the usage of PROC FORMAT in the codes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-usage-of-PROC-FORMAT-in-the-codes/m-p/234970#M43006</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;Hi guys,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am learning how to creat a barchart on an text book, and there is an example codes (for the raw data, see attached) like that&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
DATA chocolate;    
INFILE '....\Choc.txt';   
INPUT AgeGroup $ FavoriteFlavor $ @@; 
RUN;

PROC FORMAT;   
VALUE $AgeGroup 'A' = 'Adult' 'C' = 'Child'; 
RUN; 

* Bar chart for favorite flavor; 
PROC SGPLOT DATA = chocolate;  
VBAR FavoriteFlavor / GROUP = AgeGroup GROUPDISPLAY = CLUSTER;   
FORMAT AgeGroup $AgeGp.;    
LABEL FavoriteFlavor = 'Flavor of Chocolate';  
TITLE 'Favorite Chocolate Flavors by Age';
RUN; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't know what the followwing syntax (in red ) mean&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;PROC FORMAT; &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;VALUE $AgeGroup 'A' = 'Adult' 'C' = 'Child'; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;and&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;FORMAT AgeGroup $AgeGp.;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I delete these syntax&amp;nbsp;to see the what may be changed, however, it makes no difference and comes the same graph (below), Could anyone tell me what is the usage of the&amp;nbsp;above syntax&amp;nbsp;in the codes ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA chocolate;    
INFILE '....\Choc.txt';   
INPUT AgeGroup $ FavoriteFlavor $ @@; 
RUN;



* Bar chart for favorite flavor; 
PROC SGPLOT DATA = chocolate;  
VBAR FavoriteFlavor / GROUP = AgeGroup GROUPDISPLAY = CLUSTER;   
   
LABEL FavoriteFlavor = 'Flavor of Chocolate';  
TITLE 'Favorite Chocolate Flavors by Age';
RUN; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;They return the same graph like below&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/861iEACDB4E2EE126F75/image-size/large?v=mpbl-1&amp;amp;px=-1" border="0" alt="2015-11-17_085653.png" title="2015-11-17_085653.png" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2015 08:12:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-usage-of-PROC-FORMAT-in-the-codes/m-p/234970#M43006</guid>
      <dc:creator>DingDing</dc:creator>
      <dc:date>2015-11-17T08:12:36Z</dc:date>
    </item>
    <item>
      <title>Re: what is the usage of PROC FORMAT in the codes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-usage-of-PROC-FORMAT-in-the-codes/m-p/234977#M43008</link>
      <description>&lt;P&gt;Hi DingDing,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You should make yourself familiar with the important concept of formats in SAS. Beyond the SAS documentation you will find various conference papers on this topic on the web.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your program the PROC FORMAT step assigns labels 'Adult' and 'Child' to character values 'A' and 'C', respectively. The format name $AgeGroup must be used to refer to this assignment later in the program.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your FORMAT statement, however, you misspell that name as "$AgeGp" (typo in your text book?). So, at best, SAS could apply a format named $AgeGp (if existent) to the values of variable AgeGroup.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you correct the typo, you will see that in the legend of your bar&amp;nbsp;chart the abbreviated names of the age groups, 'A' and 'C' (i.e. the original values of variable AgeGroup) are replaced by the more reader-friendly labels&amp;nbsp;&lt;SPAN&gt;'Adult' and 'Child', respectively.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2015 09:31:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-usage-of-PROC-FORMAT-in-the-codes/m-p/234977#M43008</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-11-17T09:31:37Z</dc:date>
    </item>
    <item>
      <title>Re: what is the usage of PROC FORMAT in the codes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-usage-of-PROC-FORMAT-in-the-codes/m-p/234982#M43010</link>
      <description>&lt;P&gt;Hi Dingding,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I see that you have the variable that you are reading is named as "AgeGroup". Therefore, &amp;nbsp;I'd recommend changing your format name as "AgeGp" in the FORMAT statement as shown below&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA chocolate; &lt;BR /&gt;INFILE datalines; &lt;BR /&gt;INPUT AgeGroup $ FavoriteFlavor $ @@; &lt;BR /&gt;datalines;&lt;BR /&gt;A VANILLA&lt;BR /&gt;A VANILLA&lt;BR /&gt;C VANILLA&lt;BR /&gt;C CHOCOLATE&lt;BR /&gt;C CHOCOLATE&lt;BR /&gt;C CHOCOLATE&lt;BR /&gt;A CHOCOLATE&lt;BR /&gt;A STRAWBERRY&lt;BR /&gt;A FRUIT&lt;BR /&gt;A FRUIT&lt;BR /&gt;A FRUIT&lt;BR /&gt;A FRUIT&lt;BR /&gt;C FRUIT&lt;BR /&gt;A JELLY&lt;BR /&gt;A JELLY&lt;BR /&gt;C JELLY&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;PROC FORMAT; &lt;BR /&gt;VALUE $AgeGp 'A' = 'Adult' 'C' = 'Child'; &lt;BR /&gt;RUN; &lt;BR /&gt;&lt;BR /&gt;* Bar chart for favorite flavor; &lt;BR /&gt;PROC SGPLOT DATA = chocolate; &lt;BR /&gt;VBAR FavoriteFlavor / GROUP = AgeGroup GROUPDISPLAY = CLUSTER; &lt;BR /&gt;FORMAT AgeGroup $AgeGp.; &lt;BR /&gt;LABEL FavoriteFlavor = 'Flavor of Chocolate'; &lt;BR /&gt;TITLE 'Favorite Chocolate Flavors by Age';&lt;BR /&gt;RUN; &lt;/PRE&gt;&lt;P&gt;For your reference, here is the formatted legend output.....hope this helps...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/863i27F5BA9487FC8115/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="graph output.png" title="graph output.png" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="line-height: 20px;"&gt;Good luck...!!!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2015 10:18:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-usage-of-PROC-FORMAT-in-the-codes/m-p/234982#M43010</guid>
      <dc:creator>kannand</dc:creator>
      <dc:date>2015-11-17T10:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: what is the usage of PROC FORMAT in the codes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-usage-of-PROC-FORMAT-in-the-codes/m-p/234988#M43013</link>
      <description>&lt;P&gt;Hi DingDing,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good point from Kannan: Of course, you can also change the format name in the PROC FORMAT step in order to make it consistent with the name used in the FORMAT statement later. If you are not familiar with formats, it may indeed be less confusing to avoid&amp;nbsp;using the same name for variables and formats (although this is permitted, as long as the variable name does not end in a number). The advantage of having the same name (except for the leading $-sign, of course, in the case of character formats) would be that you don't have to remember another name ("Did I call it $AgeGp or $AgeGrp or ...?").&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In earlier versions of SAS (up to v8, in fact) the length of format names was restricted to 8 characters (including the leading $-sign for character formats). In those days, a format name $AgeGroup would not have been possible and, as a consequence, abbreviated format names such as $AGEGRP were very&amp;nbsp;common.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Nov 2015 10:42:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-usage-of-PROC-FORMAT-in-the-codes/m-p/234988#M43013</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2015-11-17T10:42:22Z</dc:date>
    </item>
    <item>
      <title>Re: what is the usage of PROC FORMAT in the codes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-usage-of-PROC-FORMAT-in-the-codes/m-p/234999#M43016</link>
      <description>the example is from "the little SAS book", at page 231, which is an very classical SAS book, so I suppose it should not make mistake. I comfirm that the codes are all from the book and  "$AgeGp" is not misspell, that is what makes me confused</description>
      <pubDate>Tue, 17 Nov 2015 13:35:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-usage-of-PROC-FORMAT-in-the-codes/m-p/234999#M43016</guid>
      <dc:creator>DingDing</dc:creator>
      <dc:date>2015-11-17T13:35:22Z</dc:date>
    </item>
    <item>
      <title>Re: what is the usage of PROC FORMAT in the codes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-usage-of-PROC-FORMAT-in-the-codes/m-p/235006#M43017</link>
      <description>Thanks so much, Kannand, I got what you mean!</description>
      <pubDate>Tue, 17 Nov 2015 13:46:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-usage-of-PROC-FORMAT-in-the-codes/m-p/235006#M43017</guid>
      <dc:creator>DingDing</dc:creator>
      <dc:date>2015-11-17T13:46:53Z</dc:date>
    </item>
    <item>
      <title>Re: what is the usage of PROC FORMAT in the codes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/what-is-the-usage-of-PROC-FORMAT-in-the-codes/m-p/235009#M43018</link>
      <description>Thank FreelanceReinhard, I review the book and found that the " name" in PROC FORMAT VALUE name... is created by this syntax. I misunderstand it before.</description>
      <pubDate>Tue, 17 Nov 2015 13:48:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/what-is-the-usage-of-PROC-FORMAT-in-the-codes/m-p/235009#M43018</guid>
      <dc:creator>DingDing</dc:creator>
      <dc:date>2015-11-17T13:48:48Z</dc:date>
    </item>
  </channel>
</rss>

