BookmarkSubscribeRSS Feed
Val_G
Calcite | Level 5

Hello

 

I have a large dataset and I want to use hash tables to loop thru all my clients and their decision at certain time point. Once the client has made a decision, I want to keep it for the current time period until a new decision is made. See attachment for current data and desired data.

 

Thanks!

9 REPLIES 9
Reeza
Super User
Your question is coming across a bit as more of a 'code my work for me' than a request for help. Can you post what you've tried and where you're having any issues?
Val_G
Calcite | Level 5

Here is the code I have so far. The questions I have is:

why isn't h.find_next() giving me the next value?

how can I replace the current decision by the decision from the previous line?

 

data test;

length client $1. time decision $9.;

input client time decision;

datalines;

A 1 Blank

A 2 DecisionX

A 3 Blank

B 1 DecisionY

B 2 Blank

B 3 DecisionZ

B 4 Blank

;

options mlogic ;

data hello;

dcl hash h(dataset:'test', multidata: 'y');

h.definekey('client');

h.definedata('client', 'time', 'decision');

h.definedone();

 

do while (not done) ;

set dup end =done;

rc = h.find();

if (rc = 0) then do;

put client= time= decision=;

rc = h.find_next();

do while(rc = 0);

put 'test' client= decision;

rc = h.find_next();

 

end;

end;

end;

run;

 

 

KachiM
Rhodochrosite | Level 12

What is your DUP data set? It is needed to understand your problem.

Val_G
Calcite | Level 5
no dup only test data as provided
ballardw
Super User

Since you have

do while (not done) ; 
set dup end =done;
rc = h.find();

in your code that isn't working the contents of the data set DUP mentioned here could well be the issue.

 

Val_G
Calcite | Level 5
Unfortunately, the error persists even with this new code:
data test;
length client $1. time decision $9.;
input client time decision;
datalines;
A 1 Blank
A 2 DecisionX
A 3 Blank
B 1 DecisionY
B 2 Blank
B 3 DecisionZ
B 4 Blank

;

data hello;
dcl hash h(dataset:'test', multidata: 'y');
h.definekey('client');
h.definedata('client', 'time', 'decision');
h.definedone();

do while (not done) ;
set test end =done;
rc = h.find();
if (rc = 0) then do;
put client= time= decision=;
rc = h.find_next();
do while(rc = 0);
put 'test' client= decision;
rc = h.find_next();

end;
end;
end;
run;
KachiM
Rhodochrosite | Level 12
Is this you want? If not, let us know your issue.



267  data hello;
268     dcl hash h(dataset:'test', multidata: 'y');
269     h.definekey('client');
270     h.definedata('client', 'time', 'decision');
271     h.definedone();
272
273     do while (not done) ;
274        set test end =done;
275        rc = h.find();
276        if (rc = 0) then do;
277           put client= time= decision=;
278           rc = h.find_next();
279           do while(rc = 0);
280              put 'test' client= decision;
281              rc = h.find_next();
282
283           end;
284        end;
285     end;
286  stop;
287  run;

NOTE: There were 7 observations read from the data set WORK.TEST.
client=A time=1 decision=Blank
testclient=A Blank
testclient=A DecisionX
client=A time=1 decision=Blank
testclient=A Blank
testclient=A DecisionX
client=A time=1 decision=Blank
testclient=A Blank
testclient=A DecisionX
client=B time=1 decision=DecisionY
testclient=B Blank
testclient=B DecisionZ
testclient=B Blank
client=B time=1 decision=DecisionY
testclient=B Blank
testclient=B DecisionZ
testclient=B Blank
client=B time=1 decision=DecisionY
testclient=B Blank
testclient=B DecisionZ
testclient=B Blank
client=B time=1 decision=DecisionY
testclient=B Blank
testclient=B DecisionZ
testclient=B Blank
NOTE: There were 7 observations read from the data set WORK.TEST.
KachiM
Rhodochrosite | Level 12

&colon appears when posted. It should stand for colon(:).

Val_G
Calcite | Level 5
Unfortunately, what I'm looking for would look like this:
client=A time=1 decision=Blank
testclient=A DecisionX
testclient=A DecisionX
client=B time=1 decision=DecisionY
testclient=B DecisionY
testclient=B DecisionZ
testclient=B DecisionZ

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 9 replies
  • 2200 views
  • 0 likes
  • 4 in conversation