BookmarkSubscribeRSS Feed
Barkamih
Pyrite | Level 9

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

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

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. 

Barkamih
Pyrite | Level 9

This is my data 

 

I have over one million 

 

regards 

ballardw
Super User

@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?

ballardw
Super User

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.

 

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

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
  • 4 replies
  • 590 views
  • 2 likes
  • 3 in conversation