<?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: Recode variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Recode-variables/m-p/949515#M42663</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/470091"&gt;@Ossy&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is always very helpful if your provide a sample of the actual data, following &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt; (and not Excel or screen captures). Please do this in all future questions, and even for this question. Without this sample of your data, I can only guess that the values are not character, they are numeric, and should not be enclosed in quotes. But also please keep in mind that what &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;said, you haven't told us what went wrong with your code, again we are guessing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nevertheless, here is my solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
    value maritalf 1,2,3,6,7,8='Not Married' 4,5='Married';
run;

data want;
    set have;
    format marital maritalf.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 30 Oct 2024 18:55:10 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2024-10-30T18:55:10Z</dc:date>
    <item>
      <title>Recode variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Recode-variables/m-p/949495#M42657</link>
      <description>&lt;P&gt;Can you please recode this variable for me; Married =1 and not married =2. Recode:&amp;nbsp;&lt;EM&gt;marital status&lt;/EM&gt;&amp;nbsp;([married (4,5) and not married (1,2,3,6,7,8)&lt;/P&gt;&lt;P&gt;&amp;lt; High school= 1 and not &amp;gt; High school= 2. Recode:&lt;EM&gt;&amp;nbsp;education&lt;/EM&gt;&amp;nbsp;[&amp;lt; High school (1,2)]&amp;nbsp; and [&amp;gt; High school (3,4,5,6)]&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 16:31:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Recode-variables/m-p/949495#M42657</guid>
      <dc:creator>Ossy</dc:creator>
      <dc:date>2024-10-30T16:31:37Z</dc:date>
    </item>
    <item>
      <title>Assistance with recoding variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Recode-variables/m-p/949500#M42664</link>
      <description>&lt;P&gt;Can you please recode this variable for me; Married =1 and not married =2. Recode:&amp;nbsp;&lt;EM&gt;marital status&lt;/EM&gt;&amp;nbsp;([married (4,5) and not married (1,2,3,6,7,8)&lt;/P&gt;&lt;P&gt;&amp;lt; High school= 1 and not &amp;gt; High school= 2. Recode:&lt;EM&gt;&amp;nbsp;education&lt;/EM&gt;&amp;nbsp;[&amp;lt; High school (1,2)]&amp;nbsp; and [&amp;gt; High school (3,4,5,6)]&lt;/P&gt;&lt;P&gt;I recoded the variable but did not get a positive result. Here is my recoded version. Please let me know where I made mistakes. Thanks&lt;/P&gt;&lt;P&gt;if&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;marital='4'&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;then&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;married='1';&lt;/P&gt;&lt;P&gt;else&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;if&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;marital='5'&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;then&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;married='1';&lt;/P&gt;&lt;P&gt;else&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;if&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;marital='1'&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;then&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;married='0';&lt;/P&gt;&lt;P&gt;else&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;if&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;marital='2'&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;then&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;married='0';&lt;/P&gt;&lt;P&gt;else&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;if&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;marital='3'&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;then&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;married='0';&lt;/P&gt;&lt;P&gt;else&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;if&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;marital='6'&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;then&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;married='0';&lt;/P&gt;&lt;P&gt;else&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;if&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;marital='7'&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;then&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;married='0';&lt;/P&gt;&lt;P&gt;else&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;if&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;marital='8'&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;then&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;married='0';&lt;/P&gt;&lt;P&gt;IF&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;age &amp;lt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;50&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;then&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;agey='1';&lt;/P&gt;&lt;P&gt;else&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;if&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;age &amp;gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;50&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;then&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;agey='2';&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If education &amp;lt; High school='1' then Highschool=1;&lt;/P&gt;&lt;P&gt;else if education&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&amp;lt; High school=2 then Highschool=1;&lt;/P&gt;&lt;P&gt;else&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;if&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;education &amp;gt; High school=3&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;then&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Highschool='0';&lt;/P&gt;&lt;P&gt;else&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;if&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;education &amp;gt; High school=4'&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;then&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Highschool='0';&lt;/P&gt;&lt;P&gt;else&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;if&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;education &amp;gt; High school=5'&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;then&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Highschool='0';&lt;/P&gt;&lt;P&gt;else&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;if&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;education &amp;gt; High school=6'&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;then&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Highschool='0';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 16:48:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Recode-variables/m-p/949500#M42664</guid>
      <dc:creator>Ossy</dc:creator>
      <dc:date>2024-10-30T16:48:10Z</dc:date>
    </item>
    <item>
      <title>Re: Recode variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Recode-variables/m-p/949501#M42659</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/470091"&gt;@Ossy&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Can you please recode this variable for me; Married =1 and not married =2. Recode:&amp;nbsp;&lt;EM&gt;marital status&lt;/EM&gt;&amp;nbsp;([married (4,5) and not married (1,2,3,6,7,8)&lt;/P&gt;
&lt;P&gt;&amp;lt; High school= 1 and not &amp;gt; High school= 2. Recode:&lt;EM&gt;&amp;nbsp;education&lt;/EM&gt;&amp;nbsp;[&amp;lt; High school (1,2)]&amp;nbsp; and [&amp;gt; High school (3,4,5,6)]&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What did you try?&amp;nbsp; Did it run?&amp;nbsp; If not what error did you get? Share your log.&lt;/P&gt;
&lt;P&gt;Did it run but not do what you want?&amp;nbsp; In what way was the result wrong?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not able to start? Show some example input data and the expect result for that example data.&amp;nbsp; Make sure to consider edge cases.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 17:00:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Recode-variables/m-p/949501#M42659</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-10-30T17:00:43Z</dc:date>
    </item>
    <item>
      <title>Re: Recode variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Recode-variables/m-p/949505#M42660</link>
      <description>&lt;P&gt;I'm not sure why the word "recode" is used. Custom formats would be a much better approach, doesn't require you to create a new character variable.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 17:37:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Recode-variables/m-p/949505#M42660</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-10-30T17:37:00Z</dc:date>
    </item>
    <item>
      <title>Re: Assistance with recoding variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Recode-variables/m-p/949506#M42665</link>
      <description>&lt;P&gt;DUPLICATE THREAD&lt;/P&gt;
&lt;P&gt;Moderator ... please add this thread into&amp;nbsp;&lt;A href="https://communities.sas.com/t5/New-SAS-User/Recode-variables/m-p/949495#M42657" target="_blank"&gt;https://communities.sas.com/t5/New-SAS-User/Recode-variables/m-p/949495#M42657&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 17:41:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Recode-variables/m-p/949506#M42665</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-10-30T17:41:23Z</dc:date>
    </item>
    <item>
      <title>Re: Recode variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Recode-variables/m-p/949509#M42662</link>
      <description>This is my recoded variable Data Survey;&lt;BR /&gt;Set "C:\Users\skhan\Downloads\survey.sas7bdat";&lt;BR /&gt;if marital='4' then married='1';&lt;BR /&gt;else if marital='5' then married='1';&lt;BR /&gt;else if marital='1' then married='0';&lt;BR /&gt;else if marital='2' then married='0';&lt;BR /&gt;else if marital='3' then married='0';&lt;BR /&gt;else if marital='6' then married='0';&lt;BR /&gt;else if marital='7' then married='0';&lt;BR /&gt;else if marital='8' then married='0';&lt;BR /&gt;If education &amp;lt; High school='1' then Highschool=1;&lt;BR /&gt;else if education &amp;lt; High school=2 then Highschool=1;&lt;BR /&gt;else if education &amp;gt; High school=3 then Highschool='0';&lt;BR /&gt;else if education &amp;gt; High school=4' then Highschool='0';&lt;BR /&gt;else if education &amp;gt; High school=5' then Highschool='0';&lt;BR /&gt;else if education &amp;gt; High school=6' then Highschool='0';&lt;BR /&gt;RUN;</description>
      <pubDate>Wed, 30 Oct 2024 18:10:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Recode-variables/m-p/949509#M42662</guid>
      <dc:creator>Ossy</dc:creator>
      <dc:date>2024-10-30T18:10:34Z</dc:date>
    </item>
    <item>
      <title>Re: Recode variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Recode-variables/m-p/949515#M42663</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/470091"&gt;@Ossy&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is always very helpful if your provide a sample of the actual data, following &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt; (and not Excel or screen captures). Please do this in all future questions, and even for this question. Without this sample of your data, I can only guess that the values are not character, they are numeric, and should not be enclosed in quotes. But also please keep in mind that what &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;said, you haven't told us what went wrong with your code, again we are guessing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Nevertheless, here is my solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
    value maritalf 1,2,3,6,7,8='Not Married' 4,5='Married';
run;

data want;
    set have;
    format marital maritalf.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 18:55:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Recode-variables/m-p/949515#M42663</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-10-30T18:55:10Z</dc:date>
    </item>
    <item>
      <title>Re: Recode variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Recode-variables/m-p/949545#M42666</link>
      <description>&lt;P&gt;Statements like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;If education &amp;lt; High school='1' then Highschool=1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is not going to work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you really have two separate variables named HIgh and School?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And even if you did you cannot just list two variables next to each other without any operator in between them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What are the NAMES of the variables in your SURVEY datasets? (Not the LABELS attached to the variables.)&amp;nbsp; &amp;nbsp;If the names include spaces then you will need to do two things.&lt;/P&gt;
&lt;P&gt;1) Make sure the VALIDVARNAME option is set to ANY instead of the normal setting of V7.&lt;/P&gt;
&lt;P&gt;2) Use NAME LITERALS in the code when referencing the variables with spaces (or other characters not normally allowed in names of objects in SAS).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming you did have two variables named EDUCATION and HIGHSCHOOL what would it mean to test if one is larger than the other?&amp;nbsp; Are those variables NUMERIC or CHARACTER?&amp;nbsp; If they are character then comparisons will be down lexigraphically (the first character is comparied.&amp;nbsp; If they are the same then the second character is compared. etc.&amp;nbsp; So values like '11' or '12' and less than values like '2'.)&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 22:25:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Recode-variables/m-p/949545#M42666</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-10-30T22:25:43Z</dc:date>
    </item>
    <item>
      <title>Re: Assistance with recoding variable</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Recode-variables/m-p/949550#M42667</link>
      <description>&lt;P&gt;Done.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Oct 2024 23:19:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Recode-variables/m-p/949550#M42667</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-10-30T23:19:40Z</dc:date>
    </item>
  </channel>
</rss>

