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!
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;
What is your DUP data set? It is needed to understand your problem.
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.
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.
&colon appears when posted. It should stand for colon(:).
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.