In the following code, I would like to create a character variable called "range", that takes on the value of "min_price to max_price", with min and max price equal to the min and max prices of each origin continent. How should I correct it?
proc sql;
create table stats as
select origin,
max(msrp) as max_price,
min(msrp) as min_price,
"(min_price) to (max_price)" as range
from sashelp.cars
group by 1
;
quit;
The results I'm looking for it like the following:
Origin max_price min_price range
Asia 89765 10280 10280 to 89765
Europe 192465 16999 16999 to 192465
USA 81795 10995 10995 to 81795
It helps if you show the desired results, I think this works.
proc sql;
create table stats as
select origin,
max(msrp) as max_price,
min(msrp) as min_price,
catx(' to ', put(calculated min_price, 8.1), put(calculated max_price, 8.1)) as range
from sashelp.cars
group by 1
;
quit;
Did you mean this?
proc sql;
create table stats as
select origin,msrp,ifc(max(msrp)=msrp or min(msrp)=msrp,"(min_price) to (max_price)",' ') as range
from sashelp.cars
group by 1
;
quit;
or you want this?
proc sql;
create table stats as
select origin,msrp,ifc(max(msrp)=msrp or min(msrp)=msrp,"(min_price) to (max_price)",' ') as range
from sashelp.cars
group by 1
having max(msrp)=msrp or min(msrp)=msrp
;
quit;
or something else?
I am just guessing
It helps if you show the desired results, I think this works.
proc sql;
create table stats as
select origin,
max(msrp) as max_price,
min(msrp) as min_price,
catx(' to ', put(calculated min_price, 8.1), put(calculated max_price, 8.1)) as range
from sashelp.cars
group by 1
;
quit;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.