<?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: get format values (e.g. 0=No, 1=Yes) from a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/get-format-values-e-g-0-No-1-Yes-from-a-dataset/m-p/845745#M334348</link>
    <description>&lt;P&gt;It looks like you're planning to build a data dictionary / codebook?&amp;nbsp; I would try searching lexjansen.com for papers on that subject.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Nov 2022 18:33:17 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2022-11-22T18:33:17Z</dc:date>
    <item>
      <title>get format values (e.g. 0=No, 1=Yes) from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-format-values-e-g-0-No-1-Yes-from-a-dataset/m-p/845718#M334341</link>
      <description>&lt;P&gt;Hello SAS community,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to get label and format values (e.g. 0=No, 1=Yes) from a dataset. Using dictionary tables I've been able to get the labels but the format values are proving more elusive.&lt;/P&gt;
&lt;P&gt;Below is my test dataset and the sql code I've used to get the labels.&lt;/P&gt;
&lt;P&gt;I could use some help with the format values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc format;&lt;BR /&gt;value agecat&lt;BR /&gt;0-&amp;lt; 10='0 to &amp;lt;10'&lt;BR /&gt;10-&amp;lt; 20='10 to &amp;lt;20'&lt;BR /&gt;20-&amp;lt; 30='20 to &amp;lt;30'&lt;BR /&gt;30-&amp;lt; 40='30 to &amp;lt;40'&lt;BR /&gt;40-high='40 and above';&lt;BR /&gt;value sexf &lt;BR /&gt;1='Male' &lt;BR /&gt;2='Female';&lt;BR /&gt;value racef &lt;BR /&gt;1='White'&lt;BR /&gt;2='Black'&lt;BR /&gt;3='Asian'&lt;BR /&gt;4='Native Hawaiian or Pacific Islander'&lt;BR /&gt;5='American Indian or Alaskan Native'&lt;BR /&gt;6='Asian Indian or Pacific Islander'&lt;BR /&gt;7=Prefer not to answer&lt;BR /&gt;8='Other'&lt;BR /&gt;9='&amp;gt;1 race';&lt;BR /&gt;value maritalf &lt;BR /&gt;1='Single' &lt;BR /&gt;2='Married' &lt;BR /&gt;3='Widowed' &lt;BR /&gt;4='Divorced';&lt;BR /&gt;value educf &lt;BR /&gt;1='High School or Less' &lt;BR /&gt;2='2 Yr College' &lt;BR /&gt;3='4 Yr College' &lt;BR /&gt;4='Graduate Degree';&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input id age gender race marital educ;&lt;BR /&gt;format age agecat. gender sexf. race racef. marital maritalf. educ educf.;&lt;BR /&gt;label &lt;BR /&gt;id='Subject id'&lt;BR /&gt;age='Age category'&lt;BR /&gt;gender='Reported gender'&lt;BR /&gt;race='Reported race'&lt;BR /&gt;marital='Marital status'&lt;BR /&gt;educ='Highest educational attainment';&lt;BR /&gt;cards;&lt;BR /&gt;1 9 1 1 1 1 &lt;BR /&gt;2 25 2 2 2 2 &lt;BR /&gt;3 35 1 3 2 4 &lt;BR /&gt;4 27 1 1 1 1 &lt;BR /&gt;5 18 2 1 3 1 &lt;BR /&gt;6 41 1 2 4 3 &lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;desired output&lt;/P&gt;
&lt;P&gt;Is all this output possible from dictionary tables (adding format just gives agecat., etc.) or maybe proc contents - I couldn't find any resources that would get both the numeric value and it's meaning (e.g. 1=Male) in the same column&lt;/P&gt;
&lt;TABLE width="677"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="209"&gt;
&lt;P&gt;Variable&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="213"&gt;
&lt;P&gt;Label&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="255"&gt;
&lt;P&gt;Format Values&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="209"&gt;
&lt;P&gt;id&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="213"&gt;
&lt;P&gt;Subject id&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="255"&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="209"&gt;
&lt;P&gt;age&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="213"&gt;
&lt;P&gt;Age category&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="255"&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; 0-&amp;lt; 10=0 to &amp;lt;10&lt;/P&gt;
&lt;P&gt;10-&amp;lt; 20=10 to &amp;lt;20&lt;/P&gt;
&lt;P&gt;20-&amp;lt; 30=20 to &amp;lt;30&lt;/P&gt;
&lt;P&gt;30-&amp;lt; 40=30 to &amp;lt;40&lt;/P&gt;
&lt;P&gt;40-high=40 and above&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="209"&gt;
&lt;P&gt;gender&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="213"&gt;
&lt;P&gt;Reported gender&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="255"&gt;
&lt;P&gt;1=Male&lt;/P&gt;
&lt;P&gt;2=Female&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="209"&gt;
&lt;P&gt;race&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="213"&gt;
&lt;P&gt;Reported race&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="255"&gt;
&lt;P&gt;1=White&lt;/P&gt;
&lt;P&gt;&amp;nbsp;2=Black&lt;/P&gt;
&lt;P&gt;&amp;nbsp;3=Asian&lt;/P&gt;
&lt;P&gt;&amp;nbsp;4=Native Hawaiian or Pacific Islander&lt;/P&gt;
&lt;P&gt;&amp;nbsp;5=American Indian or Alaskan Native&lt;/P&gt;
&lt;P&gt;&amp;nbsp;6=Asian Indian or Pacific Islander&lt;/P&gt;
&lt;P&gt;&amp;nbsp;7=Prefer not to answer&lt;/P&gt;
&lt;P&gt;&amp;nbsp;8=Other&lt;/P&gt;
&lt;P&gt;&amp;nbsp;9=&amp;gt;1 race&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="209"&gt;
&lt;P&gt;marital&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="213"&gt;
&lt;P&gt;Marital status&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="255"&gt;
&lt;P&gt;1=Single&lt;/P&gt;
&lt;P&gt;2=Married&lt;/P&gt;
&lt;P&gt;3=Widowed&lt;/P&gt;
&lt;P&gt;4=Divorced&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="209"&gt;
&lt;P&gt;edu&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="213"&gt;
&lt;P&gt;Highest educational attainment&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="255"&gt;
&lt;P&gt;1=High School or Less&lt;/P&gt;
&lt;P&gt;2=2 Yr College&lt;/P&gt;
&lt;P&gt;3=4 Yr College&lt;/P&gt;
&lt;P&gt;4=Graduate Degree&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance,&lt;/P&gt;
&lt;P&gt;Margaret&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 16:54:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-format-values-e-g-0-No-1-Yes-from-a-dataset/m-p/845718#M334341</guid>
      <dc:creator>urban58</dc:creator>
      <dc:date>2022-11-22T16:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: get format values (e.g. 0=No, 1=Yes) from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-format-values-e-g-0-No-1-Yes-from-a-dataset/m-p/845720#M334342</link>
      <description>&lt;P&gt;Why not just copy the text from the program that makes the format?&lt;/P&gt;
&lt;P&gt;Do you no longer have that code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If not you can ask PROC FORMAT to convert the format definitions into a dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format lib=work.formats out=formats;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can then use FMTNAME, START, END and LABEL in that dataset to generate the strings you want.&amp;nbsp; Since you are using the HIGH keyword in at least one of those formats you also might want to include the HLO variable.&lt;/P&gt;
&lt;PRE&gt;Obs    FMTNAME     START          END           HLO    LABEL

  1    AGECAT        0                    10           0 to &amp;lt;10
  2    AGECAT       10                    20           10 to &amp;lt;20
  3    AGECAT       20                    30           20 to &amp;lt;30
  4    AGECAT       30                    40           30 to &amp;lt;40
  5    AGECAT       40      HIGH                 H     40 and above
  6    EDUCF         1                     1           High School or Less
  7    EDUCF         2                     2           2 Yr College
  8    EDUCF         3                     3           4 Yr College
  9    EDUCF         4                     4           Graduate Degree
 10    MARITALF      1                     1           Single
 11    MARITALF      2                     2           Married
 12    MARITALF      3                     3           Widowed
 13    MARITALF      4                     4           Divorced
 14    RACEF         1                     1           White
 15    RACEF         2                     2           Black
 16    RACEF         3                     3           Asian
 17    RACEF         4                     4           Native Hawaiian or Pacific Islander
 18    RACEF         5                     5           American Indian or Alaskan Native
 19    RACEF         6                     6           Asian Indian or Pacific Islander
 20    RACEF         7                     7           Prefer not to answer
 21    RACEF         8                     8           Other
 22    RACEF         9                     9           &amp;gt;1 race
 23    SEXF          1                     1           Male
 24    SEXF          2                     2           Female

&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Nov 2022 17:04:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-format-values-e-g-0-No-1-Yes-from-a-dataset/m-p/845720#M334342</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-22T17:04:42Z</dc:date>
    </item>
    <item>
      <title>Re: get format values (e.g. 0=No, 1=Yes) from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-format-values-e-g-0-No-1-Yes-from-a-dataset/m-p/845733#M334343</link>
      <description>&lt;P&gt;Thanks Tom - very useful information.&lt;/P&gt;
&lt;P&gt;1. I can copy in the format values but with a lot of datasets this is very time consuming and I hoped SAS would have a better solution&lt;/P&gt;
&lt;P&gt;2. As you suggested, I converted the format definitions into a dataset&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and then created a variable for the format values&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data format_value; length format_value $50;&lt;BR /&gt;set formats(keep=FMTNAME START END LABEL);&lt;BR /&gt;if FMTNAME='SEXF' and start=1 and end=1 and label='Male' then format_value ='1=Male'; else&lt;BR /&gt;if FMTNAME='SEXF' and start=2 and end=2 and label='Female' then format_value ='1=Female';&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;getting for my format_value&lt;/P&gt;
&lt;DIV class="branch"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;1=Male&lt;/P&gt;
&lt;P&gt;2=Female&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This really works, not to ask too much but is there a more efficient way to do this?&lt;/P&gt;
&lt;P&gt;Really appreciate your fast and spot-on response - this problem has stumped me for a long time!&lt;/P&gt;
&lt;P&gt;Margaret&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 18:09:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-format-values-e-g-0-No-1-Yes-from-a-dataset/m-p/845733#M334343</guid>
      <dc:creator>urban58</dc:creator>
      <dc:date>2022-11-22T18:09:49Z</dc:date>
    </item>
    <item>
      <title>Re: get format values (e.g. 0=No, 1=Yes) from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-format-values-e-g-0-No-1-Yes-from-a-dataset/m-p/845738#M334344</link>
      <description>&lt;P&gt;No need to hard code the values!&amp;nbsp; They are already in the dataset!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For these types of simple formats you could use something like this to populate your FORMAT_VALUE variable.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set formats(keep=fmtname start end label);
  length format_value $50 ;
  if start=end then format_value = catx('=',start,quote(trim(label)));
  else format_value=catx('=',catx('-',start,end),quote(trim(label)));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1669141088357.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77563i895D48594D028A8A/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1669141088357.png" alt="Tom_0-1669141088357.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 18:18:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-format-values-e-g-0-No-1-Yes-from-a-dataset/m-p/845738#M334344</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-22T18:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: get format values (e.g. 0=No, 1=Yes) from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-format-values-e-g-0-No-1-Yes-from-a-dataset/m-p/845743#M334346</link>
      <description>Tom, you’re a super helper, many thanks!&lt;BR /&gt;Margaret&lt;BR /&gt;</description>
      <pubDate>Tue, 22 Nov 2022 18:29:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-format-values-e-g-0-No-1-Yes-from-a-dataset/m-p/845743#M334346</guid>
      <dc:creator>urban58</dc:creator>
      <dc:date>2022-11-22T18:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: get format values (e.g. 0=No, 1=Yes) from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-format-values-e-g-0-No-1-Yes-from-a-dataset/m-p/845745#M334348</link>
      <description>&lt;P&gt;It looks like you're planning to build a data dictionary / codebook?&amp;nbsp; I would try searching lexjansen.com for papers on that subject.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 18:33:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-format-values-e-g-0-No-1-Yes-from-a-dataset/m-p/845745#M334348</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-11-22T18:33:17Z</dc:date>
    </item>
    <item>
      <title>Re: get format values (e.g. 0=No, 1=Yes) from a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/get-format-values-e-g-0-No-1-Yes-from-a-dataset/m-p/845749#M334349</link>
      <description>First thing I did but I could not find (or maybe understand) how the format information was abstracted</description>
      <pubDate>Tue, 22 Nov 2022 18:38:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/get-format-values-e-g-0-No-1-Yes-from-a-dataset/m-p/845749#M334349</guid>
      <dc:creator>urban58</dc:creator>
      <dc:date>2022-11-22T18:38:32Z</dc:date>
    </item>
  </channel>
</rss>

