DATA Step, Macro, Functions and more

Reg:Update

Reply
Frequent Contributor
Posts: 140

Reg:Update

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

Super User
Posts: 10,044

Reg:Update

Posted in reply to sas_Forum

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

Frequent Contributor
Posts: 140

Reg:Update

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

Respected Advisor
Posts: 4,173

Reg:Update

Posted in reply to sas_Forum

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

Super User
Posts: 10,044

Reg:Update

Posted in reply to sas_Forum

Maybe your code is not right.

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

Ksharp

Ask a Question
Discussion stats
  • 4 replies
  • 147 views
  • 0 likes
  • 3 in conversation