BookmarkSubscribeRSS Feed
collegestudent2
Fluorite | Level 6

I am trying to create a cumulative counter variable that tracks the total number games. The code I have been using can be found below. I am not sure how to word it so that the TotalGames column adds 1 for each new game, sorted by date. That way that the count is totaled based on the dates the games were played. 

 

PROC SORT data = NewRoseBowl;
by Date;
RUN; 

 

Data CountRoseBowl;
set NewRoseBowl;
TotalGames + 1;
by Date;
if first.date then TotalGames = 1;
PROC PRINT;
Format Date WEEKDATE30.;
RUN;

2 REPLIES 2
mkeintz
PROC Star

Do you want the total number of games for each date?

 

If so, why not run a PROC FREQ on the DATE variable?

 

No need for sorting, or a data step.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
BrianB4233
Obsidian | Level 7
It looks like you need to add the name of the variable that indicates what the game is, as in:

proc sort;
by game_type date;
run;

data CountRoseBowl;
set NewRoseBowl;
by game_type date;

/* set up counter */
if first.date then game_cnt = 1;
else game_cnt + 1;

/* output last record by GAME_TYPE to get total sum */
if last.game_type;
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
  • 669 views
  • 0 likes
  • 3 in conversation