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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1049 views
  • 0 likes
  • 3 in conversation