BookmarkSubscribeRSS Feed
Mikkel_madsen
Obsidian | Level 7

Hi,

 

I want to create a count variable. I have the following dataset:

 

ID         GPS         Open          Store

1          4321          Y                1

1          3421          Y                2

1          2321          N               1

2          1235          Y               4

2          1242          N               2

3          1235          N               2

 

The new dataset should look like:

 

ID         GPS         Open          Store      Count

1          4321          Y                1             3

1          3421          Y                2             3

1          2321          N               1              3

2          1235          Y               4              2

2          1242          N               2              2

3          1235          N               2              1

 

So the new variable 'count' counts the number of observations with the same ID.

 

Thanks! 

1 REPLY 1
ed_sas_member
Meteorite | Level 14

Hi @Mikkel_madsen 

Please try this:

proc sql;
	create table want as
	select *, Count(id) as count
	from have
	group by id;
quit;

Best,

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 687 views
  • 0 likes
  • 2 in conversation