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
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;
Please post test data in the form of a datastep:
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 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.