<?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 Using If Statement to Create Variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-If-Statement-to-Create-Variable/m-p/786557#M251155</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a character variable, SmokingStatus, with these values: "Never Smoker","Former Smoker","Light Smoker", and&amp;nbsp;"Heavy Smoker". I am trying to assign them numbers so I can interpret them easier in a regression:&lt;/P&gt;&lt;PRE&gt;DATA SubQ.dataclean3;&lt;BR /&gt;&lt;BR /&gt;	LENGTH SmokingStatus $22.&lt;BR /&gt;			Smoking 8.;&lt;BR /&gt;	&lt;BR /&gt;	SET SubQ.combined;&lt;BR /&gt;		&lt;BR /&gt;		IF SmokingStatus="*Unknown" THEN Smoking_Status=' '; /* Highlight missing values */&lt;BR /&gt;		IF SmokingStatus="Never Smoker" THEN Smoking=0; /* Change smoking group to easier variable to use in regression */&lt;BR /&gt;		IF SmokingStatus="Former Smoker" THEN Smoking=1;&lt;BR /&gt;		IF Smoking_Status="Light Smoker" THEN Smoking=2;&lt;BR /&gt;		IF Smoking_Status="Heavy Smoker" THEN Smoking=3;&lt;BR /&gt;	&lt;BR /&gt;	RUN;&lt;/PRE&gt;&lt;P&gt;The problem is they assign 0 and 1 correctly but not 2 and 3; for light and heavy smokers, Smoking is shown as missing. Does anyone know why this is? I have also tried this making Smoking a character variable with $22. length and quotations around the number values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Fri, 17 Dec 2021 21:21:05 GMT</pubDate>
    <dc:creator>leackell13</dc:creator>
    <dc:date>2021-12-17T21:21:05Z</dc:date>
    <item>
      <title>Using If Statement to Create Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-If-Statement-to-Create-Variable/m-p/786557#M251155</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a character variable, SmokingStatus, with these values: "Never Smoker","Former Smoker","Light Smoker", and&amp;nbsp;"Heavy Smoker". I am trying to assign them numbers so I can interpret them easier in a regression:&lt;/P&gt;&lt;PRE&gt;DATA SubQ.dataclean3;&lt;BR /&gt;&lt;BR /&gt;	LENGTH SmokingStatus $22.&lt;BR /&gt;			Smoking 8.;&lt;BR /&gt;	&lt;BR /&gt;	SET SubQ.combined;&lt;BR /&gt;		&lt;BR /&gt;		IF SmokingStatus="*Unknown" THEN Smoking_Status=' '; /* Highlight missing values */&lt;BR /&gt;		IF SmokingStatus="Never Smoker" THEN Smoking=0; /* Change smoking group to easier variable to use in regression */&lt;BR /&gt;		IF SmokingStatus="Former Smoker" THEN Smoking=1;&lt;BR /&gt;		IF Smoking_Status="Light Smoker" THEN Smoking=2;&lt;BR /&gt;		IF Smoking_Status="Heavy Smoker" THEN Smoking=3;&lt;BR /&gt;	&lt;BR /&gt;	RUN;&lt;/PRE&gt;&lt;P&gt;The problem is they assign 0 and 1 correctly but not 2 and 3; for light and heavy smokers, Smoking is shown as missing. Does anyone know why this is? I have also tried this making Smoking a character variable with $22. length and quotations around the number values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Dec 2021 21:21:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-If-Statement-to-Create-Variable/m-p/786557#M251155</guid>
      <dc:creator>leackell13</dc:creator>
      <dc:date>2021-12-17T21:21:05Z</dc:date>
    </item>
    <item>
      <title>Re: Using If Statement to Create Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-If-Statement-to-Create-Variable/m-p/786559#M251156</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;IF SmokingStatus="*Unknown" THEN Smoking_Status=.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Numeric missing is . (a dot)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;{EDIT:} sorry didn't spot the issue. You are missing _ in the variable name:&lt;/P&gt;
&lt;PRE&gt;SmokingStatus is not the same as Smoking_Status &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;{EDIT2:} The length statement should be like:&lt;/P&gt;
&lt;PRE&gt;LENGTH SmokingStatus $ 22 Smoking 8;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Fri, 17 Dec 2021 21:41:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-If-Statement-to-Create-Variable/m-p/786559#M251156</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-12-17T21:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using If Statement to Create Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-If-Statement-to-Create-Variable/m-p/786562#M251157</link>
      <description>&lt;P&gt;The spelling must match exactly, including any non-printable characters that might be contained in the string. Print the string with a $HEX format to reveal such characters.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Dec 2021 21:43:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-If-Statement-to-Create-Variable/m-p/786562#M251157</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-12-17T21:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: Using If Statement to Create Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-If-Statement-to-Create-Variable/m-p/786563#M251158</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/407085"&gt;@leackell13&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a character variable, SmokingStatus, with these values: "Never Smoker","Former Smoker","Light Smoker", and&amp;nbsp;"Heavy Smoker".&lt;STRONG&gt; I am trying to assign them numbers so I can interpret them easier in a regression:&lt;/STRONG&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;How do you think that coding these to numbers will make it easier to interpret your results? They're categorical variables so need to be included in a CLASS statement and then the output would be labeled as "Never Smoker" vs "Heavy Smoker" compared to 1 vs 3? The first version would be much easier to read.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you planning to treat these as a continuous ordinal variable instead of categorical?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/407085"&gt;@leackell13&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a character variable, SmokingStatus, with these values: "Never Smoker","Former Smoker","Light Smoker", and&amp;nbsp;"Heavy Smoker". I am trying to assign them numbers so I can interpret them easier in a regression:&lt;/P&gt;
&lt;PRE&gt;DATA SubQ.dataclean3;&lt;BR /&gt;&lt;BR /&gt;	LENGTH SmokingStatus $22.&lt;BR /&gt;			Smoking 8.;&lt;BR /&gt;	&lt;BR /&gt;	SET SubQ.combined;&lt;BR /&gt;		&lt;BR /&gt;		IF SmokingStatus="*Unknown" THEN Smoking_Status=' '; /* Highlight missing values */&lt;BR /&gt;		IF SmokingStatus="Never Smoker" THEN Smoking=0; /* Change smoking group to easier variable to use in regression */&lt;BR /&gt;		IF SmokingStatus="Former Smoker" THEN Smoking=1;&lt;BR /&gt;		IF Smoking_Status="Light Smoker" THEN Smoking=2;&lt;BR /&gt;		IF Smoking_Status="Heavy Smoker" THEN Smoking=3;&lt;BR /&gt;	&lt;BR /&gt;	RUN;&lt;/PRE&gt;
&lt;P&gt;The problem is they assign 0 and 1 correctly but not 2 and 3; for light and heavy smokers, Smoking is shown as missing. Does anyone know why this is? I have also tried this making Smoking a character variable with $22. length and quotations around the number values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Dec 2021 21:51:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-If-Statement-to-Create-Variable/m-p/786563#M251158</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-17T21:51:18Z</dc:date>
    </item>
    <item>
      <title>Re: Using If Statement to Create Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-If-Statement-to-Create-Variable/m-p/786564#M251159</link>
      <description>That is a good point; I think I was afraid that the values would be too large. So under the CLASS statement, I can just put SmokingStatus (REF='Never Smoker')?&lt;BR /&gt;</description>
      <pubDate>Fri, 17 Dec 2021 21:57:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-If-Statement-to-Create-Variable/m-p/786564#M251159</guid>
      <dc:creator>leackell13</dc:creator>
      <dc:date>2021-12-17T21:57:55Z</dc:date>
    </item>
    <item>
      <title>Re: Using If Statement to Create Variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-If-Statement-to-Create-Variable/m-p/786565#M251160</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/407085"&gt;@leackell13&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;That is a good point; I think I was afraid that the values would be too large. So under the CLASS statement, I can just put SmokingStatus (REF='Never Smoker')?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, that is how you'd specify a reference level.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would also add PARAM=REF to indicate that you're using the One hot encoding/dummy variables/Referential parameterization instead of GLM which is the SAS default.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Dec 2021 22:03:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-If-Statement-to-Create-Variable/m-p/786565#M251160</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-12-17T22:03:43Z</dc:date>
    </item>
  </channel>
</rss>

