Could someone familiar with sas change sql into data step.thank you for your attention
proc sql noprint;
create table temp as
select A.a,A.b,A.c,A.d,
put(datepart(A.e),YYMMDDN8.) as e,
case when A.f is null then calculated e
else A.f end as f,
put(datepart(A.g),YYMMDDN8.) as g,
put(datepart(A.h),YYMMDDN8.) as h,
B.city,
B.channel
from tableA(where=("20150501" le batch_date le "20150519")) A
left join (select distinct a,f,city,channel from tableB) B
on A.a=B.a
order by 1;
quit;
As a variant to what @Jagadishkatam posted.
You will need to add a least a NODUPKEY to the 2nd sort in order to replicate the DISTINCT in the SQL sub-select.
You will also need to control from which source data set same named columns get read.
proc sort data=tablea out=_tablea;
by a;
where "20150501" le batch_date le "20150519";
run;
proc sort data=tableb(keep=a f city channel) out=_tableb nodupkey;
by a f city channel;
run;
data want(drop=_:);
merge
_tablea(
in=ina
keep=a b c d e f g h
rename=(e=_e g=_g h=_h)
)
_tableb(
in=inb
keep=a city channel
)
;
by a;
if ina;
length e g h $8;
e=put(datepart(_e),YYMMDDN8.);
g=put(datepart(_g),YYMMDDN8.);
h=put(datepart(_h),YYMMDDN8.);
if missing(f) then f=e;
run;
N.B: You haven't provided sample data so above code is not tested.
proc sort data=tablea;
by a;
where "20150501" le batch_date le "20150519";
run;
proc sort data=tableb;
by a;
run;
data temp;
merge tablea(in=ina) tableb(in=inb);
by a;
if ina;
run;
As a variant to what @Jagadishkatam posted.
You will need to add a least a NODUPKEY to the 2nd sort in order to replicate the DISTINCT in the SQL sub-select.
You will also need to control from which source data set same named columns get read.
proc sort data=tablea out=_tablea;
by a;
where "20150501" le batch_date le "20150519";
run;
proc sort data=tableb(keep=a f city channel) out=_tableb nodupkey;
by a f city channel;
run;
data want(drop=_:);
merge
_tablea(
in=ina
keep=a b c d e f g h
rename=(e=_e g=_g h=_h)
)
_tableb(
in=inb
keep=a city channel
)
;
by a;
if ina;
length e g h $8;
e=put(datepart(_e),YYMMDDN8.);
g=put(datepart(_g),YYMMDDN8.);
h=put(datepart(_h),YYMMDDN8.);
if missing(f) then f=e;
run;
N.B: You haven't provided sample data so above code is not tested.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.