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!

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 6 replies
  • 3263 views
  • 4 likes
  • 3 in conversation