BookmarkSubscribeRSS Feed
R_Win
Calcite | Level 5
i have a data set

Data m;
input id name $;
cards;
1 Raju
2 nani
2 nani
2 kool
3 india
4 usa
4usa
4usa
5 uk
run;

Now i want the out put into other dataset with out coming of one duplicates to another dataset.the output shd be like this

id name
1 Raju
2 kool
3 india
5 uk

As the 2nani, and 4,usa are alredy repeted that observations shd not come to the new dataset
Message was edited by: Main Message was edited by: Main
5 REPLIES 5
deleted_user
Not applicable
Hi,

u will get the desired output by using the following code.


Data m;
input id name $;
cards;
1 Raju
2 nani
2 nani
2 nani
3 india
4 usa
4 usa
4 usa
5 uk
run;
proc sort data=m;
by id;
run ;

data m_new;
set m;
by id;
if first.id ne 1 or last.id ne 1 then delete;
else if first.id then output;
run;
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
After sorting your data file in desired order with a BY variable list, then use a DATA step with the two statements IF FIRST. and also IF LAST. to identify totally unique one-occurence data conditions, and output those to one file, while also outputting the others to a separate file.

Have a look at the SAS support http://support.sas.com/ website and its SEARCH facility, to search on the words:

duplicate by variable

and you will find both SAS product documentation and technical reference papers on the topic.


Scott Barry
SBBWorks, Inc.
GertNissen
Barite | Level 11
proc summary data=m n;
by id name;
output out=freq(where=(_FREQ_=1);
run;
ssas
Calcite | Level 5
HI,
why can't you try this

proc sort data=a nodupkey out=b;
by id name;
run;

data c;
set b;
if first.id eq 1 then output c;
run;

or


a simple way

proc sql;
create table c as select distinct id,name from b;
quit;


hope it may help you
sams
deleted_user
Not applicable
as your data appear to be approximately in order, you could try[pre] data reduced ;
set m ;
by id NOTSORTED ;
if last.id ;
run ;[/pre]This returns the last row in the current order, for each ID.

PeterC

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 5 replies
  • 693 views
  • 0 likes
  • 5 in conversation