BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ipsum
Calcite | Level 5

 

I have a dataset that looks like the following:

 

ID      MONTH      VAR

1       1                 2

1       2                 2

1       3                 1

2       1                 2

2       2                 2

2       3                 2 

3       1                 1

3       2                 1 

3       3                 1 

 

I need to get a count of ID's where VAR=1 for at least one of the months.

I'm not a very advanced user.

Is there code that could easily accomplish what I'm looking for?

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

This might be the easiest way:

 

proc sql;

select count(distinct id) from your_dataset where var=1;

quit;

 

View solution in original post

2 REPLIES 2
SuryaKiran
Meteorite | Level 14

If you need just the count then use PROC SQL.

 

data one;

infile datalines;

input ID MONTH VAR;

datalines;

1 1 2

1 2 2

1 3 1

2 1 2

2 2 2

2 3 2

3 1 1

3 2 1

3 3 1

;

run;

 

proc sql;

select distinct count(id) INTO: count

from one

where var=1 and month=1;

quit;

Thanks,
Suryakiran
Astounding
PROC Star

This might be the easiest way:

 

proc sql;

select count(distinct id) from your_dataset where var=1;

quit;

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 3822 views
  • 1 like
  • 3 in conversation