BookmarkSubscribeRSS Feed
Nieves
Quartz | Level 8

Hello SAS expert,

 

I have a dataset as follows and I want to create a variable count_var1 that reports the number of nonzero value of var1 for each month

month var1

1        5

1        0

1        3

2        0

2        7

2        0

3        9

3        0

3        6

4       10

4        0

4        0

5        7

5        4

5        0

6        8

6        7

6        9

 

so count_var1 would be

month count_var1 

1        2

 

2        1

 

3        2

 

4        1

 

5        2

 

6        3

 

May I ask you kind help on how to implement this ? 

 

Thanks 

2 REPLIES 2
Jagadishkatam
Amethyst | Level 16
proc sql;
create table want as select month,count(var1) as count_var1 from have where var1 ne 0 group by month;
quit;
Thanks,
Jag
Reeza
Super User

Proc freq data = have;

where var1 ne 0;

table month /out = want ;

run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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