<?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: How and where do I add labels to recoded variables? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-and-where-do-I-add-labels-to-recoded-variables/m-p/814553#M321507</link>
    <description>&lt;P&gt;Use a format to display 0/1 values as text:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input marriage;
datalines;
.
1
2
3
4
5
;

proc format;
value marital_status
  1 = "married"
  0 = "not married"
;
run;

data want;
set have;
if marriage in (2,3,4,5)
then cr_marital = 0;
else cr_marital = marriage; /* covers 1 and missing */
format cr_marital marital_status.;
label cr_marital = 'Care Recipient Marital Status';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In your real data, assign the label for edu_numeric in the same way as for cr_marital.&lt;/P&gt;
&lt;P&gt;BTW&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;edu_numeric = edu + 0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is fully equivalent to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;edu_numeric = edu;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 21 May 2022 12:49:58 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2022-05-21T12:49:58Z</dc:date>
    <item>
      <title>How and where do I add labels to recoded variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-and-where-do-I-add-labels-to-recoded-variables/m-p/814552#M321506</link>
      <description>&lt;P&gt;I've recoded the marriage variable to represent 1 = married and 0 = not remarried. How and where may I add a labels "married" and " not "married"? I also want to label edu_numeric as "CR Education"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Set ICPNEED.data_trim4;&lt;BR /&gt;edu_numeric = edu + 0;&lt;BR /&gt;If marriage = 1 then cr_marital = 1 "married";&lt;BR /&gt;Else&lt;BR /&gt;if marriage = 2 then cr_marital = 0 "not married";&lt;BR /&gt;Else&lt;BR /&gt;if marriage = 3 then cr_marital = 0;&lt;BR /&gt;Else&lt;BR /&gt;if marriage = 4 then cr_marital = 0;&lt;BR /&gt;Else&lt;BR /&gt;if marriage = 5 then cr_marital = 0;&lt;BR /&gt;Else&lt;BR /&gt;if marriage = . then cr_marital = .;&lt;BR /&gt;Label cr_marital = 'Care Recipient Marital Status';&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;</description>
      <pubDate>Sat, 21 May 2022 12:19:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-and-where-do-I-add-labels-to-recoded-variables/m-p/814552#M321506</guid>
      <dc:creator>gtucke1</dc:creator>
      <dc:date>2022-05-21T12:19:45Z</dc:date>
    </item>
    <item>
      <title>Re: How and where do I add labels to recoded variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-and-where-do-I-add-labels-to-recoded-variables/m-p/814553#M321507</link>
      <description>&lt;P&gt;Use a format to display 0/1 values as text:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input marriage;
datalines;
.
1
2
3
4
5
;

proc format;
value marital_status
  1 = "married"
  0 = "not married"
;
run;

data want;
set have;
if marriage in (2,3,4,5)
then cr_marital = 0;
else cr_marital = marriage; /* covers 1 and missing */
format cr_marital marital_status.;
label cr_marital = 'Care Recipient Marital Status';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In your real data, assign the label for edu_numeric in the same way as for cr_marital.&lt;/P&gt;
&lt;P&gt;BTW&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;edu_numeric = edu + 0;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is fully equivalent to&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;edu_numeric = edu;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 21 May 2022 12:49:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-and-where-do-I-add-labels-to-recoded-variables/m-p/814553#M321507</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-05-21T12:49:58Z</dc:date>
    </item>
    <item>
      <title>Re: How and where do I add labels to recoded variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-and-where-do-I-add-labels-to-recoded-variables/m-p/814563#M321515</link>
      <description>&lt;P&gt;Labels are attached to variables (or also there a dataset labels).&lt;/P&gt;
&lt;P&gt;So if you want to attach a label to CR_MARITAL that explains how it is coded you might do something like;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;label cr_martial = 'Marriage status 1=Married 0=Not Married';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I think what you are really looking is a way to display the VALUES in a special way.&amp;nbsp; That is what a FORMAT is for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want a format that displays 1 as Married and 0 as Not Married then define a format that does that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value marital
  0='Not Married' 
  1='Married'
  other='Unkown'
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then attach that format to any variable whose values you want to display that way.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format cr_marital marital.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note you can use the same format for as many variables that use the same coding.&amp;nbsp; For example if you a dataset that also had marital status for the parents you could the MARITAL format for those variables also.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that if you are coding a lot of binary variables it might just be easier to make a YESNO format instead and use it for all of them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;
  value yesno 0='No' 1='Yes' ;
run;

proc freq data=have;
  tables married dead active ;
  format married dead active yesno.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 21 May 2022 15:03:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-and-where-do-I-add-labels-to-recoded-variables/m-p/814563#M321515</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-21T15:03:18Z</dc:date>
    </item>
  </channel>
</rss>

