- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What is your DUP data set? It is needed to understand your problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
&colon appears when posted. It should stand for colon(:).
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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