<?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: proc format - Use a table to make it more dynamic in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-format-Use-a-table-to-make-it-more-dynamic/m-p/889401#M351393</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/288757"&gt;@TBS1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More questions? That's what we're here for — well, I can't speak for&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;— but ask away!&lt;/P&gt;</description>
    <pubDate>Tue, 15 Aug 2023 17:30:40 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-08-15T17:30:40Z</dc:date>
    <item>
      <title>proc format - Use a table to make it more dynamic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-format-Use-a-table-to-make-it-more-dynamic/m-p/887951#M350818</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;I would like to use the proc format in a more dynamic way.&lt;/P&gt;&lt;P&gt;Instead of&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;STRONG&gt;proc format;
    value points_range
        25-high='High'
        15-&amp;lt;25='Medium'
        other ='Low';
run;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;I would like to reference a table I created earlier to make it more dynamic. There are two variables in the table: One is a comparison value and the second contains the desired assignment value.&lt;/P&gt;&lt;P&gt;Something like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;STRONG&gt;proc format;
    value points_range
        $referenceTable1.var1 = $referenceTabl1.var2
run;&lt;/STRONG&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;Is this possible? Is *this* the way to go? Is there a better way?&lt;/P&gt;&lt;P&gt;Does anyone have a hint for me?&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2023 20:38:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-format-Use-a-table-to-make-it-more-dynamic/m-p/887951#M350818</guid>
      <dc:creator>TBS1</dc:creator>
      <dc:date>2023-08-04T20:38:08Z</dc:date>
    </item>
    <item>
      <title>Re: proc format - Use a table to make it more dynamic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-format-Use-a-table-to-make-it-more-dynamic/m-p/887953#M350820</link>
      <description>&lt;P&gt;In this tiny example, making it dynamic doesn't really buy you much. For larger situations, you can make PROC FORMAT more dynamic by creating formats from a SAS data set. Example: &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/n1e19y6lrektafn1kj6nbvhus59w.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/n1e19y6lrektafn1kj6nbvhus59w.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2023 20:44:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-format-Use-a-table-to-make-it-more-dynamic/m-p/887953#M350820</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-04T20:44:44Z</dc:date>
    </item>
    <item>
      <title>Re: proc format - Use a table to make it more dynamic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-format-Use-a-table-to-make-it-more-dynamic/m-p/887975#M350823</link>
      <description>&lt;P&gt;SAS can use a data set to make formats as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt; indicates.&amp;nbsp; The option is CNTLIN=datasetname&lt;/P&gt;
&lt;P&gt;There are some caveats:&lt;/P&gt;
&lt;P&gt;The variables used by proc format to create have specific names and you must use them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc format will also make a data set that can be used to document the formats or to be used. You may want to look at such using a format or two that you have written to see the details.&lt;/P&gt;
&lt;PRE&gt;proc format cntlout=fmtout;
    value points_range
        25-high='High'
        15-&amp;lt;25='Medium'
        other ='Low';
run;&lt;/PRE&gt;
&lt;P&gt;Basically you provide the name of the format, the type, 'C' for character, 'N' for numeric, start for the beginning of a range, End for the end of the range and Label for the format displayed values.&lt;/P&gt;
&lt;P&gt;When you are using options such as Other you will want to look at the HLO variable. that variable is used to indicate if the range includes H (high), L (low) or O (other).&amp;nbsp; If your ranges exclude one of the end points then you look at the variables SEXCL (Y or N for start exclude ) and EEXCL(Y or N for end exclude ). Your &amp;lt;25 is an EEXCL=Y.&lt;/P&gt;
&lt;P&gt;If you get into any of the more complex formats I suggest making small examples like this (don't us a lot of ranges) and create the CNTLOUT set and examine each observation carefully.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For Formats with an OTHER&amp;nbsp; do not actually have Start and End values supplied by you, that will display with the HLO=O set.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Aug 2023 21:53:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-format-Use-a-table-to-make-it-more-dynamic/m-p/887975#M350823</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-04T21:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: proc format - Use a table to make it more dynamic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-format-Use-a-table-to-make-it-more-dynamic/m-p/889400#M351392</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;!&lt;/P&gt;&lt;P&gt;Your contributions have led me in the right direction, though they have not entirely answered my cause. Thanks anyway, they really helped me a lot!&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2023 17:26:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-format-Use-a-table-to-make-it-more-dynamic/m-p/889400#M351392</guid>
      <dc:creator>TBS1</dc:creator>
      <dc:date>2023-08-15T17:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: proc format - Use a table to make it more dynamic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-format-Use-a-table-to-make-it-more-dynamic/m-p/889401#M351393</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/288757"&gt;@TBS1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;More questions? That's what we're here for — well, I can't speak for&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;— but ask away!&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2023 17:30:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-format-Use-a-table-to-make-it-more-dynamic/m-p/889401#M351393</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-08-15T17:30:40Z</dc:date>
    </item>
    <item>
      <title>Re: proc format - Use a table to make it more dynamic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-format-Use-a-table-to-make-it-more-dynamic/m-p/889406#M351394</link>
      <description>&lt;P&gt;One trick is to use CNTLOUT to see the data set that SAS creates when you create a format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you can see how you need to structure your data set though not all the details are usually required. Here's an example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*fake data to work with;
data sample;
    do x=1 to 30;
        y=x;
        output;
    end;
run;

*create format;
proc format;
    value points_range 25-high='High' 15-&amp;lt;25='Medium' other='Low';
run;

*export format to dataset;
proc format cntlout=want;
    select points_range;
run;

*view format;
proc print data=want;
    var start end label fmtname type hlo;
run;

*create new dataset from minimal variables;
data example;
    set want;
    fmtname='points_range_ex';
run;

*create format with new name;
proc format cntlin=example;
run;

*display sample data with formats to check output;
proc print data=sample;
    var x y;
    format x points_range. y points_range_ex.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Aug 2023 17:55:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-format-Use-a-table-to-make-it-more-dynamic/m-p/889406#M351394</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-08-15T17:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: proc format - Use a table to make it more dynamic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-format-Use-a-table-to-make-it-more-dynamic/m-p/889422#M351407</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much! &lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thank you for the offer! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; May I then perhaps refer to another question? I'm not sure if there might not be a better approach than the one I have thought of: &lt;A href="https://communities.sas.com/t5/SAS-Programming/Excel-export-with-format/m-p/889420#M351405" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Excel-export-with-format/m-p/889420#M351405&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2023 19:10:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-format-Use-a-table-to-make-it-more-dynamic/m-p/889422#M351407</guid>
      <dc:creator>TBS1</dc:creator>
      <dc:date>2023-08-15T19:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: proc format - Use a table to make it more dynamic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-format-Use-a-table-to-make-it-more-dynamic/m-p/889435#M351418</link>
      <description>&lt;P&gt;To make this format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
    value points_range
        25-high='High'
        15-&amp;lt;25='Medium'
        other ='Low';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Your dataset needs at a minimum two numbers and three strings.&amp;nbsp; &amp;nbsp;But to make the ranges you need both the start and the end values.&amp;nbsp; Since it is easier to remember then to predict the future let's assume the source data looks like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ranges;
  input cutpoint label $40.;
cards;
25 High
15 Medium
.  Low
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since your format is equivalent to this one:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;value xx
 low-&amp;lt;15 = 'Low'
 15-&amp;lt;25 = 'Medium'
 25-high = 'High'
 ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;We can generate a CNTLIN type dataset to define such a format from the cut points using code like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data formats;
  set ranges  end=eof;
  fmtname='points_range';
  start=cutpoint;
  end=lag(cutpoint);
  sexcl='N';
  eexcl='Y';
  if missing(start) then hlo='L';
  if missing(end) then do; 
    hlo='H';
    eexcl='N';
  end;
run;

proc format cntlin=formats ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;----------------------------------------------------------------------------
|                   FORMAT NAME: POINTS_RANGE LENGTH: 6                    |
|   MIN LENGTH:   1  MAX LENGTH:  40  DEFAULT LENGTH:   6  FUZZ: STD       |
|--------------------------------------------------------------------------|
|START           |END             |LABEL  (VER. 9.4     15AUG2023:16:48:34)|
|----------------+----------------+----------------------------------------|
|LOW             |              15&amp;lt;Low                                     |
|              15|              25&amp;lt;Medium                                  |
|              25|HIGH            |High                                    |
----------------------------------------------------------------------------


----------------------------------------------------------------------------
|       FORMAT NAME: XX       LENGTH:    6   NUMBER OF VALUES:    3        |
|   MIN LENGTH:   1  MAX LENGTH:  40  DEFAULT LENGTH:   6  FUZZ: STD       |
|--------------------------------------------------------------------------|
|START           |END             |LABEL  (VER. V7|V8   15AUG2023:16:48:34)|
|----------------+----------------+----------------------------------------|
|LOW             |              15&amp;lt;Low                                     |
|              15|              25&amp;lt;Medium                                  |
|              25|HIGH            |High                                    |
----------------------------------------------------------------------------
&amp;#12;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Aug 2023 20:52:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-format-Use-a-table-to-make-it-more-dynamic/m-p/889435#M351418</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-15T20:52:12Z</dc:date>
    </item>
  </channel>
</rss>

