BookmarkSubscribeRSS Feed
sas_Forum
Calcite | Level 5

data  Run_Dt;
  informat stdate enddate date9.;
  input  stdate enddate comm_cou $;
  format stdate enddate ddmmyy10.;
  cards;
12mar2011 13mar2011 usa
12mar2011 13mar2011 ind
run;


data  Curr_dt;
  informat stdate enddate date9.;
  input  stdate enddate comm_cou $;
  format stdate enddate ddmmyy10.;
  cards;
19mar2011 20mar2011 usa
run;

Hi i want to update the table Run_dt with Curr_dt table  where comm_cou=comm_cou

Output Table Run_Dt
19mar2011 20mar2011 usa
12mar2011 13mar2011 ind

4 REPLIES 4
Ksharp
Super User

Here is a SQL method. If you concern about speed, then Hash Table is a better way.

data  Run_Dt;
  informat stdate enddate date9.;
  input  stdate enddate comm_cou $;
  format stdate enddate ddmmyy10.;
  cards;
12mar2011 13mar2011 usa
12mar2011 13mar2011 ind
;
run;


data  Curr_dt;
  informat stdate enddate date9.;
  input  stdate enddate comm_cou $;
  format stdate enddate ddmmyy10.;
  cards;
19mar2011 20mar2011 usa
;
run;

proc sql;
update run_dt as a
  set stdate=(select stdate from curr_dt ),
  enddate=(select enddate from curr_dt)
   where  comm_cou=(select comm_cou from curr_dt as b where a.comm_cou=b.comm_cou) ;
  quit;








data  Run_Dt;
  informat stdate enddate date9.;
  input  stdate enddate comm_cou $;
  format stdate enddate ddmmyy10.;
  cards;
12mar2011 13mar2011 usa
12mar2011 13mar2011 ind
;
run;


data  Curr_dt;
  informat stdate enddate date9.;
  input  stdate enddate comm_cou $;
  format stdate enddate ddmmyy10.;
  cards;
19mar2011 20mar2011 usa
;
run;

data run_dt;
 if _n_ eq 1 then do;
  if 0 then set curr_dt;
  declare hash ha(dataset:'curr_dt',hashexp:16);
   ha.definekey('comm_cou');
   ha.definedata('stdate','enddate');
   ha.definedone();
  end;
 set run_dt;
 rc=ha.find();
 drop rc;
run;








Ksharp

sas_Forum
Calcite | Level 5

Actually i have done the by using update but i am getting only 1 Row,How can i do the same in update with getting the second row ..now i am getting only one row

                                            1     19/03/2011    20/03/2011      usa  

But i want like this by using the update statemnet.

Output Table Run_Dt
19mar2011 20mar2011 usa
12mar2011 13mar2011 ind

Patrick
Opal | Level 21

I prefer the solutions Ksharp proposed, but o.k:

data  Run_Dt;
  informat stdate enddate date9.;
  input  stdate enddate comm_cou $;
  format stdate enddate ddmmyy10.;
  cards;
12mar2011 13mar2011 usa
12mar2011 13mar2011 ind
run;


data  Curr_dt;
  informat stdate enddate date9.;
  input  stdate enddate comm_cou $;
  format stdate enddate ddmmyy10.;
  cards;
19mar2011 20mar2011 usa
run;

proc sort data=Run_dt;
  by comm_cou;
run;

proc sort data=Curr_dt;
  by comm_cou;
run;

data Run_Dt;
  update Run_Dt Curr_dt;
  by comm_cou;
run;

proc print data=Run_Dt;
run;

Instead of UPDATE you could also use MODIFY to update the table "in place": http://support.sas.com/documentation/cdl/en/lestmtsref/63323/HTML/default/viewer.htm#n0g9jfr4x5hgsfn...

Ksharp
Super User

Maybe your code is not right.

Patrick has given you an example. You can refer to it.

Ksharp

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
  • 4 replies
  • 745 views
  • 0 likes
  • 3 in conversation