BookmarkSubscribeRSS Feed
Vaibhav_Kalra
Calcite | Level 5

Hi

I have got a data with 20 columns and i want categorize the data using Proc SQL as per below

 

If Amount spent is less than 100 than "A"

If Amount spent is between 100 and 200 than "B"

If Amount spent is greater than 200 than "C"

 

Thanks

 

3 REPLIES 3
Oligolas
Barite | Level 11

Hi,

 

use the case Expression as explained here

 

________________________

- Cheers -

Kurt_Bremser
Super User
proc sql;
create table want as
select
  a.*,
  case
    when amount < 100 then 'A'
    when 100 <= amount <= 200 then 'B'
    when amount > 200 then 'C'
  end as category
from have a;
quit;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Please post test data in the form of a datastep:

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

 

And what you want to see out at the end, otherwise we are guessing on both.  You say you have 20 columns, but never mention what these are, how they are used or any relevance to the code.  You state using SQL, but do not give any reasons for this - SQL is built to run on normalised data - i.e. few columns, lots of observations - and as such isn't a good tool for lots of columns.  Datastep and an array would be easier - obviously  still guessing as no information provided.  Its likely that you could just format the value with a custom format and avoid all conditional programming at all.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 805 views
  • 0 likes
  • 4 in conversation