Hi All ,
I have the below dataset
data x;
input source $3. fare destination $3.;
datalines;
mum 500 del
del 500 mum
kol 600 che
che 600 kol
;
run;
i want only one oservation for a source and destination ie one obs for to and fro journey for ex out of del and mum and mum to del i need only one, same as for others .
the output should be like this
mum 500 del
kol 600 che
thanks
for the help in advance
How about:
data want;
set x;
length forwards backwards $200.;
forwards=catx(',',source,destination);
backwards=catx(',',destination,source);
if forwards=lag(forwards) or forwards=lag(backwards) then delete;
run;
How about:
data want;
set x;
length forwards backwards $200.;
forwards=catx(',',source,destination);
backwards=catx(',',destination,source);
if forwards=lag(forwards) or forwards=lag(backwards) then delete;
run;
Thanks RW9
Is there some order you need to consider ?
data x; input source $3. fare destination $3.; datalines; mum 500 del del 500 mum kol 600 che che 600 kol ; run; data x; set x; s=source; d=destination; call sortc(s,d); run; proc sort data=x out=want nodupkey;by s d;run;
Xia Keshan
Hi Xai ,
thanks for the help and its fine we dont need any order .
thanks
If your incoming data:
1. already have duplicates
2. same pair of "from-to" do not cluster together (could be any where in the table),
Then to use the solution by , or the following:
data x;
input source $3. fare destination $3.;
datalines;
mum 500 del
del 500 mum
kol 600 che
che 600 kol
;
run;
proc sql;
create table want (drop=grp n) as
select *, ifc(source <= destination, cats(source, destination), cats(destination,source)) as grp, monotonic() as n from x
group by grp
having n=min(n)
;
quit;
Haikuo
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.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.