BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mj5
Obsidian | Level 7 mj5
Obsidian | Level 7

 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;
1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

View solution in original post

3 REPLIES 3
Kurt_Bremser
Super User

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1537 views
  • 1 like
  • 3 in conversation