BookmarkSubscribeRSS Feed
milts
Pyrite | Level 9
data fa_sample;
id = 1;
valid_from = '01JAN2009:00:00:00'dt;
valid_to = '02FEB2009:00:00:00'dt;
format valid_from nldatm. valid_to nldatm.;
run;

data sp_sample;
id = 1;
valid_from = '01JAN2009:00:00:00'dt;
valid_to = '31DEC9999:00:00:00'dt;
format

data sp_sample;
modify sp_sample;
put valid_to=;
if _N_ = 1 then do;
declare hash h(dataset:"fa_sample");
h.definekey("id","valid_from");
h.definedata("valid_to");
h.definedone();
end;
rc = h.find();
put valid_to=; /* value is 02FEB2009:00:00:00 but when i'm viewing the dataset value is 31DEC9999:00:00:00 pa rin*/
replace;
format valid_from nldatm. valid_to nldatm.;
run;

what am i doing wrong in my data steps? the dataset is not updated

thanks a lot! 🙂
3 REPLIES 3
milts
Pyrite | Level 9
got it working already no need for replace;

the final code goes like this:

data sp_sample;
dsid=open("fa_sample","i");
dsid=close(dsid);

declare hash h(dataset:"fa_sample");
h.definekey("id","valid_from");
h.definedata("valid_to");
h.definedone();

modify sp_sample;
rc = h.find();
format valid_from nldatm. valid_to nldatm.;
run;

i just don't get it yet why i have to use the open function first. is it because the read access of modify is not the same when using set or update?

thanks!
DanielSantos
Barite | Level 11
Actually you don't.

The only requirement is to include in the PDV (Program Data Vector) the complete dataset layout before declaring the hash. The open function will do just that, allocate in the PDV the dataset layout.

You could substitute:

dsid=open("fa_sample","i");
dsid=close(dsid);

For:

if 0 then set fa_sample;

Now, this is kind of a trick, this will set the dataset (alocate layout into the PDV) without actually reading any row from it (if 0, will always evaluate to false).

Both codes will do exactly the same.

Cheers from Portugal.

Daniel Santos @ www.cgd.pt.
milts
Pyrite | Level 9
thanks for the tip Daniel. learned something new today.

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
  • 646 views
  • 0 likes
  • 2 in conversation