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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: