I have hash object datastep and in that need to create a variable like domain="SE" but it is not happening. any reason where i did something wrong. any guidance?
data se; set startdates; by usubjid descending startdate descending taetord element; if _n_=0 then set enddates raw.ta; if _N_ = 1 then do; declare hash lastdate(dataset:"enddates"); lastdate.definekey("usubjid"); lastdate.definedata("dsendtc"); lastdate.definedone(); declare hash Tarm(dataset:"raw.TA"); Tarm.definekey("ETCD"); Tarm.definedata("EPOCH"); Tarm.definedone(); end; length oldstart $20; retain oldstart; SESTDTC=scan(DSSTDTC,1,'T'); rc1=Tarm.find(); if not first.usubjid then do; SEENDTC=scan(oldstart,1,'T'); end; else do; rc=lastdate.find(); if rc=0 then SEENDTC=scan(DSENDTC,1,'T'); end; if missing(sestdtc) and not missing(seendtc) then delete; if SEENDTC>SESTDTC or first.usubjid then output; oldstart=DSSTDTC; rename TAETORD=SESEQ; domain='SE'; drop rc rc1 dsstdtc startdate enddate domain tatrans tabranch oldstart dsendtc arm armcd TESTRL; run;
Whilst its great to use new technology, would it not be simpler, and far easier to read to just do two steps here:
proc sort data=enddates nodupkey; by usubjid descending dsendtc; run; data se; merge raw.ta enddates; by usubjid; ... /* Do you other processing here */ run;
Its only worth using some technology if there is a benefit to the code for using that technology, and in this case the task can be taken care of with simpler, shorter code (and most likely with less memory overhead). Avoid using something just for the purpose of using it.
When you have a problem:
- post the complete log of the step (or excerpts if same messages are repeated)
- example data to run the code against. Use a data step with datalines.
Whilst its great to use new technology, would it not be simpler, and far easier to read to just do two steps here:
proc sort data=enddates nodupkey; by usubjid descending dsendtc; run; data se; merge raw.ta enddates; by usubjid; ... /* Do you other processing here */ run;
Its only worth using some technology if there is a benefit to the code for using that technology, and in this case the task can be taken care of with simpler, shorter code (and most likely with less memory overhead). Avoid using something just for the purpose of using it.
And if you're just after a quick method to do a lookup without sorting, consider using formats created from raw.ta and enddates.
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 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.
Ready to level-up your skills? Choose your own adventure.