BookmarkSubscribeRSS Feed
gazp23
Calcite | Level 5

Hi

 

I'm trying to create a new column called "MONTH_COUNT", whcih will look across a row of data and count how many values are greater than 0.  The full table has around 9,000 rows and 40 rows (monthly totals and varioius flags to categorise customers).

 

My current data set looks like-

Customer MAR-17 APR-17 MAY-17

A                    0           0           100

B                    10           10          10

C                    50         70          75

 

Desired output-

Customer MONTH_COUNT MAR-17 APR-17 MAY-17

A                        1                    0            0           100

B                        3                  10           10          10

C                        3                  50          70           75

 

Thanks in advance!

 

Gaz

1 REPLY 1
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Well, its by using arrays.  The longer version is (and this is not tested as you have not provided test data in the form of a datastep so I nothing to work with nor knowledge of structure):

data want;
  set have;
  array values{3} mar17 apr17 may17;
  do i=1 to 3;
    if values{i} > 0 then month_count=sum(month_count,1);
  end;
run;

 

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 1 reply
  • 5655 views
  • 0 likes
  • 2 in conversation