code for repeated data

Reply
Contributor
Posts: 29

code for repeated data

[ Edited ]

Hi

This is Ibrahim researcher student at UCD in Ireland

I’m looking for code that will solve this issue

look at COW_ID COLUMN

I want to make a new column which represents how many time each observation repeated in column  

For example, if the number 72050556 repeated six times in my original  dataset column, I would like to print a number 6 in the new column in front of these numbers (72050556) as well as the other repeating times

 

BEST REGARDS

 

Ibrahim

PROC Star
Posts: 1,070

Re: code for repeated data

post sample data in the form of a datastep if you want a code answer. 

 

PROC FREQ or PROC SQL are probably your best choices. 

Contributor
Posts: 29

Re: code for repeated data

This is my data 

 

I have over one million 

 

regards 

Super User
Posts: 12,148

Re: code for repeated data


Barkamih wrote:

This is my data 

 

I have over one million 

 

regards 


Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.

 

Best is to either provide a data step to create data and another to show the desired result for the example data, or provide an example using a SAS supplied data set.

 

Did you look at the example in my other post?

Super User
Posts: 12,148

Re: code for repeated data

If I understand your request then there are two parts involved: 1 is count the number of times a value occurs and the second is to merge that value back onto the original data.

 

Here's one way with a SAS supplied data set you can test.

proc sql;
   create table want as
   select a.*, b.agecount
   from sashelp.class as a
        left join
        (select age, count(*) as agecount
         from sashelp.class
         group by age) as b
        on a.age=b.age
   ;
quit;

It is best to post text as text pasted into a code box. Many users here do not want to open Microsoft format documents as security risks and others have organization policy or software that prevents them from opening such from unapproved sources.

 

Ask a Question
Discussion stats
  • 4 replies
  • 145 views
  • 2 likes
  • 3 in conversation