<?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: Need help debugging IF/THEN/ELSE ranged variables in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Need-help-debugging-IF-THEN-ELSE-ranged-variables/m-p/689653#M24679</link>
    <description>&lt;P&gt;If that screenshot is the exact code you ran, there are several problems:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You're missing some spaces between keywords and variable names (e.g. "IFSBP" and "90THENSBPHypCat"); that will never work.&lt;/LI&gt;
&lt;LI&gt;The range syntax is not quite correct.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Try this instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.MISSISSIPPI_VS;
    input SSN: $11. VisitDate Height Weight SBP DBP;
    datalines;
    000-00-0000 18504 65 153 111 72 
    000-00-0000 18861 65 158 109 75 
    000-00-0000 19236 65 151 115 74 
    000-00-0000 19606 65 154 107 79 
    000-00-0000 19978 65 153 110 74 
    ;
run;

data want;
    set mississippi_vs;
    format SBPHypCat $32.;
    if SBP = .                  then SBPHypCat = ' ';
    else if SBP lt 90           then SBPHypCat = 'Below Normal';
    else if 90 le SBP lt 120    then SBPHypCat = 'Normal';
    else if 120 le SBP lt 140   then SBPHypCat = 'High Normal';
    else if 140 le SBP lt 160   then SBPHypCat = 'Stage 1 Hypertension';
    else if 160 le SBP lt 180   then SBPHypCat = 'Stage 2 Hypertension';
    else if 180 le SBP          then SBPHypCat = 'Stage 3 Hypertension';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Oct 2020 18:07:35 GMT</pubDate>
    <dc:creator>mklangley</dc:creator>
    <dc:date>2020-10-07T18:07:35Z</dc:date>
    <item>
      <title>Need help debugging IF/THEN/ELSE ranged variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-debugging-IF-THEN-ELSE-ranged-variables/m-p/689638#M24676</link>
      <description>&lt;P&gt;Hi all;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;I'm trying to create a new set of variables using IF/THEN/ELSE statements, but I'm receiving an error saying that there's a syntax error and one saying that the statement is not valid. See below for example code (using SAS Studio 9.4 M6).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;So far, I've verified the correct variable names and spellings, the specified ranges do not overlap, and each statement appears to be independent of one another. My sense is that there's a minor piece missing, rather than several lines of code, but any assistance is welcomed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="sasSource"&gt;data WORK.MISSISSIPPI_LT;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;infile datalines dsd truncover;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;input SSN:$11. VisitDate:32. Height:32. Weight:32. SBP:32. DBP:32.;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;datalines;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;000-00-0000 18504 65 153 111 72&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;000-00-0000 18861 65 158 109 75&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;000-00-0000 19236 65 151 115 74&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;000-00-0000 19606 65 154 107 79&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;000-00-0000 19978 65 153 110 74&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;;;;;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="sasSource"&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Error in Code.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50278iE95AA10CDDA170FA/image-size/large?v=v2&amp;amp;px=999" role="button" title="Error in Code.png" alt="Error in Code.png" /&gt;&lt;/span&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 10 Dec 2020 15:13:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-debugging-IF-THEN-ELSE-ranged-variables/m-p/689638#M24676</guid>
      <dc:creator>dwrightii</dc:creator>
      <dc:date>2020-12-10T15:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: Need help debugging IF/THEN/ELSE ranged variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-debugging-IF-THEN-ELSE-ranged-variables/m-p/689647#M24678</link>
      <description>&lt;P&gt;It appears that your code does not have space characters between elements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;90THENSBPHypCat&lt;/P&gt;
&lt;P&gt;should be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;90 THEN SBPHypCat&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you copied that code from somewhere else then you may have characters that in some file formats appear to be spaces but are not used as such in the editor/ code parse by SAS.&lt;/P&gt;
&lt;P&gt;I also suspect that you have copied some code from a Proc Format example because the - &amp;lt; is not normally used for comparison in data step code. Maybe.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When including error messages include 1) The entire Procedure or DATA step code and 2) copy the text from the log with the messages and errors. Paste into a code box opened on the forum with the &amp;lt;/&amp;gt; icon to preserve formatting of the diagnostic characters such as the underscores.&lt;/P&gt;
&lt;P&gt;It is much easier to suggest changes by copy/paste and edit code than from pictures.&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>Wed, 07 Oct 2020 17:56:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-debugging-IF-THEN-ELSE-ranged-variables/m-p/689647#M24678</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-07T17:56:17Z</dc:date>
    </item>
    <item>
      <title>Re: Need help debugging IF/THEN/ELSE ranged variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-debugging-IF-THEN-ELSE-ranged-variables/m-p/689653#M24679</link>
      <description>&lt;P&gt;If that screenshot is the exact code you ran, there are several problems:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You're missing some spaces between keywords and variable names (e.g. "IFSBP" and "90THENSBPHypCat"); that will never work.&lt;/LI&gt;
&lt;LI&gt;The range syntax is not quite correct.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Try this instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.MISSISSIPPI_VS;
    input SSN: $11. VisitDate Height Weight SBP DBP;
    datalines;
    000-00-0000 18504 65 153 111 72 
    000-00-0000 18861 65 158 109 75 
    000-00-0000 19236 65 151 115 74 
    000-00-0000 19606 65 154 107 79 
    000-00-0000 19978 65 153 110 74 
    ;
run;

data want;
    set mississippi_vs;
    format SBPHypCat $32.;
    if SBP = .                  then SBPHypCat = ' ';
    else if SBP lt 90           then SBPHypCat = 'Below Normal';
    else if 90 le SBP lt 120    then SBPHypCat = 'Normal';
    else if 120 le SBP lt 140   then SBPHypCat = 'High Normal';
    else if 140 le SBP lt 160   then SBPHypCat = 'Stage 1 Hypertension';
    else if 160 le SBP lt 180   then SBPHypCat = 'Stage 2 Hypertension';
    else if 180 le SBP          then SBPHypCat = 'Stage 3 Hypertension';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 18:07:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-debugging-IF-THEN-ELSE-ranged-variables/m-p/689653#M24679</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2020-10-07T18:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: Need help debugging IF/THEN/ELSE ranged variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-debugging-IF-THEN-ELSE-ranged-variables/m-p/689657#M24681</link>
      <description>&lt;P&gt;Thanks for the reply; unfortunately I'll still need a hand. I'm not sure why the log says there are no spaces, but there are (see photo). I am also attaching the full log, in case there is anything else there that can help. &lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Post Followup.png" style="width: 998px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50283i304661EA51691098/image-size/large?v=v2&amp;amp;px=999" role="button" title="Post Followup.png" alt="Post Followup.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 18:14:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-debugging-IF-THEN-ELSE-ranged-variables/m-p/689657#M24681</guid>
      <dc:creator>dwrightii</dc:creator>
      <dc:date>2020-10-07T18:14:26Z</dc:date>
    </item>
    <item>
      <title>Re: Need help debugging IF/THEN/ELSE ranged variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-debugging-IF-THEN-ELSE-ranged-variables/m-p/689659#M24682</link>
      <description>&lt;P&gt;Thank you for the reply. Fair point; I missed the name that's in the length statement. That's been updated. Also, the spaces are there; somehow the log is reporting they're not there (see above picture). I tried adding additional space, just in case, but no change. As for the operators, my guess is that's where the issue is coming into play.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 18:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-debugging-IF-THEN-ELSE-ranged-variables/m-p/689659#M24682</guid>
      <dc:creator>dwrightii</dc:creator>
      <dc:date>2020-10-07T18:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: Need help debugging IF/THEN/ELSE ranged variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-debugging-IF-THEN-ELSE-ranged-variables/m-p/689661#M24683</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/344531"&gt;@dwrightii&lt;/a&gt;&amp;nbsp;Here's another way to do it, using a PROC FORMAT:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WORK.MISSISSIPPI_VS;
    input SSN: $11. VisitDate Height Weight SBP DBP;
    datalines;
    000-00-0000 18504 65 153 25 72 
    000-00-0000 18861 65 158 95 75 
    000-00-0000 19236 65 151 125 74 
    000-00-0000 19606 65 154 140 79 
    000-00-0000 19978 65 153 161 74 
    000-00-0000 19978 65 153 214 74 
    ;
run;

proc format;    
    value SBP_format .           = ' '
                    low - &amp;lt; 90   = 'Below Normal'
                    90 - &amp;lt; 120   = 'Normal'
                    120 - &amp;lt; 140  = 'High Normal'
                    140 - &amp;lt; 160  = 'Stage 1 Hypertension'
                    160 - &amp;lt; 180  = 'Stage 2 Hypertension'
                    180 - high   = 'Stage 3 Hypertension'
    ;
run;

data want2;
    set mississippi_vs;
    SBPHypCat = put(SBP,SBP_format.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(Note: I made up some dummy SBP values, to test each of the cases.)&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 18:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-debugging-IF-THEN-ELSE-ranged-variables/m-p/689661#M24683</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2020-10-07T18:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: Need help debugging IF/THEN/ELSE ranged variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-debugging-IF-THEN-ELSE-ranged-variables/m-p/689663#M24684</link>
      <description>&lt;P&gt;Looks like your code came into contact with a word processor and now has "funny" spaces. Your best bet is to delete it and retype it by hand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are also trying to use PROC FORMAT syntax in a data step. Change the conditions to (example)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if 90 le sbp lt 120 then sbphypcat = "Normal";&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 07 Oct 2020 18:25:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-debugging-IF-THEN-ELSE-ranged-variables/m-p/689663#M24684</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-10-07T18:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: Need help debugging IF/THEN/ELSE ranged variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-debugging-IF-THEN-ELSE-ranged-variables/m-p/689756#M24690</link>
      <description>&lt;P&gt;That idea will definitely work well, although this particular data set is a bit too large to go the datalines route . Still, that is good to know for my other projects - thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 21:47:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-debugging-IF-THEN-ELSE-ranged-variables/m-p/689756#M24690</guid>
      <dc:creator>dwrightii</dc:creator>
      <dc:date>2020-10-07T21:47:47Z</dc:date>
    </item>
    <item>
      <title>Re: Need help debugging IF/THEN/ELSE ranged variables</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-debugging-IF-THEN-ELSE-ranged-variables/m-p/689763#M24692</link>
      <description>&lt;P&gt;Thanks to everyone for your help. Here is what I ended up going with:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IF SBP = . THEN SBPHypCat = ' ';&lt;BR /&gt;ELSE IF SBP &amp;lt; 90 THEN SBPHypCat = 'Below Normal';&lt;BR /&gt;ELSE IF SBP &amp;lt; 120 THEN SBPHypCat = 'Normal';&lt;BR /&gt;ELSE IF SBP &amp;lt; 140 THEN SBPHypCat = 'High Normal';&lt;BR /&gt;ELSE IF SBP &amp;lt; 160 THEN SBPHypCat = 'Stage 1 Hypertension';&lt;BR /&gt;ELSE IF SBP &amp;lt; 180 THEN SBPHypCat = 'Stage 2 Hypertension';&lt;BR /&gt;ELSE SBPHypCat = 'Stage 3 Hypertension';&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2020 22:31:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-debugging-IF-THEN-ELSE-ranged-variables/m-p/689763#M24692</guid>
      <dc:creator>dwrightii</dc:creator>
      <dc:date>2020-10-07T22:31:58Z</dc:date>
    </item>
  </channel>
</rss>

