BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AMMAN
Obsidian | Level 7
data work.ifthen;
set work.pelicanstores;
if Net_Sales < 50 THEN Sales = "0-$50";
ELSE IF Net_Sales > 51 AND < 100 Sales = "$51-$100";
ELSE IF Net_Sales > 100 AND <200 Sales = "$101-$200";
ELSE IF Net_Sales > 200 Sales ="$200+";

Run;

I run clear through the IF, but I am getting an error on my first ELSE . 

 

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,
              a missing value, arrayname, (, +, -, INPUT, NOT, PUT, ^, _NEW_, ~.  

 

I cannot figure out what's wrong with my syntax.  Can anyone help? 

 

My objective is to group Net_Sales into categories so they display nicely on Cross Tab.

 

Thanks for your help

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

if the above works, make sure to add a length statement for sales to accommodate the values and avoid truncation

View solution in original post

6 REPLIES 6
novinosrin
Tourmaline | Level 20

see if this correction helps:

 


data work.ifthen;
set work.pelicanstores;
if Net_Sales < 50 THEN Sales = "0-$50";
ELSE IF Net_Sales > 51 AND Net_Sales< 100 then  Sales = "$51-$100";
ELSE IF Net_Sales > 100 AND Net_Sales<200 then Sales = "$101-$200";
ELSE IF Net_Sales > 200 then  Sales ="$200+";

Run;

or

 

data work.ifthen;
set work.pelicanstores;
if Net_Sales < 50 THEN Sales = "0-$50";
ELSE IF   51<  Net_Sales< 100 then  Sales = "$51-$100";
ELSE IF  100<  Net_Sales<200 then Sales = "$101-$200";
ELSE IF Net_Sales > 200 then  Sales ="$200+";

Run;

 

novinosrin
Tourmaline | Level 20

if the above works, make sure to add a length statement for sales to accommodate the values and avoid truncation

AMMAN
Obsidian | Level 7
You read my mind!
AMMAN
Obsidian | Level 7

One step closer!   I am getting some weird results in the new variable.  Why is the second part missing?

 

weird results.JPG

 

 

data_null__
Jade | Level 19

@AMMAN wrote:
data work.ifthen;
set work.pelicanstores;
if Net_Sales < 50 THEN Sales = "0-$50";
ELSE IF Net_Sales > 51 AND < 100 Sales = "$51-$100";
ELSE IF Net_Sales > 100 AND <200 Sales = "$101-$200";
ELSE IF Net_Sales > 200 Sales ="$200+";

Run;

 

 

 


Your ranges have gaps LT 50 then GT 51.  Also the labels are not clear  "0-$50" but 50 is not included in the range.

 

I would use a VALUE format

 

proc format;
   value sales 
      0    - 50    = '$0-$50'
      50<  - 100   = '>$50-$100'
      100< - 200   = '>$100-$200'
      200  - high  = '200+'
      ;
   quit; 
AMMAN
Obsidian | Level 7

Thanks for your help!