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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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