<?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 How to recode a categorical variable and got a few error messages in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-recode-a-categorical-variable-and-got-a-few-error/m-p/715917#M80101</link>
    <description>&lt;P&gt;&lt;FONT color="#0000FF"&gt;Hello all,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;I am a newbie to SAS and trying to recode a categorical variable in different ways; however, none of them worked.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;I still have not figured out how to fix this problem.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;What I want to do is to c&lt;SPAN&gt;reate a new variable (4 categories) based on an old variable's responses (8 categories).&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;I tried several ways, but none of them worked. I attached my codes below. &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;1. I used the format and added $ before the variable name because B5 ends with the number. ( I am not sure if I understand this correctly)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value $B5
'increased a lot'='increased'
'increased somewhat'='increased'
'increased a litte'='increased'
'stayed the same'='stayed the same'
'decreased a litte'='decreased'
'decreased somewhat'='decreased'
'decreased a lot'='decreased'
'N/A'='N/A'
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I got an error message:&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="berylsky1_1-1612223369508.png" style="width: 446px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54227i874FE39CB91DDA2F/image-dimensions/446x132?v=v2" width="446" height="132" role="button" title="berylsky1_1-1612223369508.png" alt="berylsky1_1-1612223369508.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;2. I used the if/then statement here.&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;Data risk3; /**create a new dataset**/
Set risk2;
If B5 in ('stayed the same') then B5_R='stayed the same';
If B5 in ('increased a lot' 'increased somewhat' 'increased a little') then B5_R='increased';
If B5 in ('decreased a little' 'decreased somewhat' 'decreased a lot') then B5_R='decreased';
If B5 in ('N/A') then B5_R='N/A';
If B5=. then B5_R=.;
run;&lt;/PRE&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;When running this code, I got the long notes:&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;DIV class="sasNote"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="berylsky1_0-1612223330210.png" style="width: 790px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54226iF69434F8EF9BDF57/image-dimensions/790x79?v=v2" width="790" height="79" role="button" title="berylsky1_0-1612223330210.png" alt="berylsky1_0-1612223330210.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&lt;FONT color="#000000"&gt;I googled how to recode a categorical variable for a few hours and got stuck on this problem. &lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&lt;FONT color="#000000"&gt;Please share your suggestions to solve this problem.&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&lt;FONT color="#000000"&gt;Thank you for your help.&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 01 Feb 2021 23:49:54 GMT</pubDate>
    <dc:creator>berylsky1</dc:creator>
    <dc:date>2021-02-01T23:49:54Z</dc:date>
    <item>
      <title>How to recode a categorical variable and got a few error messages</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-recode-a-categorical-variable-and-got-a-few-error/m-p/715917#M80101</link>
      <description>&lt;P&gt;&lt;FONT color="#0000FF"&gt;Hello all,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;I am a newbie to SAS and trying to recode a categorical variable in different ways; however, none of them worked.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;I still have not figured out how to fix this problem.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;What I want to do is to c&lt;SPAN&gt;reate a new variable (4 categories) based on an old variable's responses (8 categories).&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;I tried several ways, but none of them worked. I attached my codes below. &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;1. I used the format and added $ before the variable name because B5 ends with the number. ( I am not sure if I understand this correctly)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value $B5
'increased a lot'='increased'
'increased somewhat'='increased'
'increased a litte'='increased'
'stayed the same'='stayed the same'
'decreased a litte'='decreased'
'decreased somewhat'='decreased'
'decreased a lot'='decreased'
'N/A'='N/A'
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I got an error message:&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="berylsky1_1-1612223369508.png" style="width: 446px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54227i874FE39CB91DDA2F/image-dimensions/446x132?v=v2" width="446" height="132" role="button" title="berylsky1_1-1612223369508.png" alt="berylsky1_1-1612223369508.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;&lt;SPAN&gt;2. I used the if/then statement here.&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;PRE&gt;Data risk3; /**create a new dataset**/
Set risk2;
If B5 in ('stayed the same') then B5_R='stayed the same';
If B5 in ('increased a lot' 'increased somewhat' 'increased a little') then B5_R='increased';
If B5 in ('decreased a little' 'decreased somewhat' 'decreased a lot') then B5_R='decreased';
If B5 in ('N/A') then B5_R='N/A';
If B5=. then B5_R=.;
run;&lt;/PRE&gt;&lt;P&gt;&lt;FONT color="#0000FF"&gt;When running this code, I got the long notes:&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;DIV class="sasNote"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="berylsky1_0-1612223330210.png" style="width: 790px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/54226iF69434F8EF9BDF57/image-dimensions/790x79?v=v2" width="790" height="79" role="button" title="berylsky1_0-1612223330210.png" alt="berylsky1_0-1612223330210.png" /&gt;&lt;/span&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&lt;FONT color="#000000"&gt;I googled how to recode a categorical variable for a few hours and got stuck on this problem. &lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&lt;FONT color="#000000"&gt;Please share your suggestions to solve this problem.&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasNote"&gt;&lt;FONT color="#000000"&gt;Thank you for your help.&amp;nbsp;&lt;/FONT&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Feb 2021 23:49:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-recode-a-categorical-variable-and-got-a-few-error/m-p/715917#M80101</guid>
      <dc:creator>berylsky1</dc:creator>
      <dc:date>2021-02-01T23:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to recode a categorical variable and got a few error messages</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-recode-a-categorical-variable-and-got-a-few-error/m-p/715920#M80102</link>
      <description>&lt;P&gt;The format name must end with a letter or an underscore, then you may use it to recode your variable&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value $B5_FORMAT
'increased a lot'='increased'
'increased somewhat'='increased'
'increased a litte'='increased'
'stayed the same'='stayed the same'
'decreased a litte'='decreased'
'decreased somewhat'='decreased'
'decreased a lot'='decreased'
'N/A'='N/A'
;
run;

Data risk3; /**create a new dataset**/
Set risk2;
length B5_R $16;
B5_R = input(B5, ?? $B5_FORMAT.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note The ?? prevents SAS from generating warnings when the format can't be applied. It quietly produces a missing value (" ") instead.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 00:23:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-recode-a-categorical-variable-and-got-a-few-error/m-p/715920#M80102</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2021-02-02T00:23:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to recode a categorical variable and got a few error messages</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-recode-a-categorical-variable-and-got-a-few-error/m-p/715921#M80103</link>
      <description>&lt;P&gt;First you &lt;STRONG&gt;cannot&lt;/STRONG&gt; Name a format ending in digits. If you remember things like other formats such as F the digits are the display width. So the same applies to custom formats. You could try naming your format B5_ if you really like the 5 as part of the name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, on this forum please include the entire procedure or data step from the log when asking questions about it. Copy the entire text of the submitted code along with all the notes, warnings or other messages. Then on the forum open a text box and paste the text.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The note means that you have used a variable that is character in a fashion reserved for numeric variables.&lt;/P&gt;
&lt;P&gt;I can't copy and paste as you are showing pictures and incomplete data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Part of this could come from "if B5 = . ". Your B5 appears to be character. If you want to test to see if a value is missing use the Missing function instead. Do not assign missing to character values with " = . " Either use a literal blank ='' or use the call missing function.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 10:44:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-recode-a-categorical-variable-and-got-a-few-error/m-p/715921#M80103</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-03T10:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to recode a categorical variable and got a few error messages</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-recode-a-categorical-variable-and-got-a-few-error/m-p/716303#M80109</link>
      <description>&lt;P&gt;Thank you for your help! I found the error and changed it, and based on your advice; I will include the entire data step for the next question.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 03:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-recode-a-categorical-variable-and-got-a-few-error/m-p/716303#M80109</guid>
      <dc:creator>berylsky1</dc:creator>
      <dc:date>2021-02-03T03:54:44Z</dc:date>
    </item>
  </channel>
</rss>

