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
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
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
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...
Maybe your code is not right.
Patrick has given you an example. You can refer to it.
Ksharp
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.