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!

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 5 replies
  • 829 views
  • 0 likes
  • 3 in conversation