BookmarkSubscribeRSS Feed
Bharat_P
Fluorite | Level 6
proc so;
create table sample as 
select make
          ,type
          ,count(case when flag="euro" then MEET end) as Euro
          ,sum(case when flag="euro" then Invoice end) as Done
from help.cars
group by 1,2
;
quit;

need to convert this to hash coding. if someone can help the it will be great( writing sql as so, sashelp as help,msrp as Meet as I am not being able to paste codes which are grammatically incorrect.

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Hi @Bharat_P.

 

Can you provide some sample data and what your desired result look like?

Astounding
PROC Star

There are two major reasons why your request is not possible.

 

First, you ask for hashing.  Hashing is a DATA step tool only, and cannot be used within PROC SQL.  So you can pick one or the other, but not both.

 

Second, you tell us that the code you posted doesn't work.  But you assume that we know what it is supposed to accomplish.  That's your job, to explain what the result is going to be, especially when your code doesn't work. 

 

Taking an educated guess at half of the problem (the INVOICE part), you noted that this doesn't work:

 ,sum(case when flag="euro" then Invoice end) as Done

I'm guessing that this is what is needed instead:

 ,sum((flag="euro") * Invoice) as Done

Perhaps you can test that (without the MEET logic that doesn't work) to see if it does part of what you want.  But the logic for MEET is much more obscure and you will need to explain what you want.

 

Bharat_P
Fluorite | Level 6

Actually the msg got misinterpreted.Sorry for that. My task is to convert this code to hash object from SQL. This code is running fine but my job is to look for ways to convert the codes into hash objects

Patrick
Opal | Level 21

@Bharat_P wrote:

Actually the msg got misinterpreted.Sorry for that. My task is to convert this code to hash object from SQL. This code is running fine but my job is to look for ways to convert the codes into hash objects


1. The code you've posted is NOT running fine but returns errors. Please fix the code so we can understand the logic you're after.

2. As @Kurt_Bremser writes this doesn't look like a good application for the SAS data step hash object so why would you want to go for such an approach in first place - unless that's an exercise.

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 804 views
  • 3 likes
  • 5 in conversation