BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
apolitical
Obsidian | Level 7

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 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

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;
novinosrin
Tourmaline | Level 20

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

apolitical
Obsidian | Level 7
I included the desired dataset I want in the original post. Thanks.
Reeza
Super User

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;
apolitical
Obsidian | Level 7
That works. Thank you!

SAS Innovate 2025: Register Now

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1057 views
  • 0 likes
  • 3 in conversation