I actually like this question as an interview question. It quickly demonstrates if a programmer understands a data step and by group functionality. It's definitely not something that's required but there are various reasons to do a running total or lagged data and this demonstrates both ideas.
Its also a very basic level of understanding and can easily verify if a programmers skill is at the level they claim during an interview process.
It's also kind of amusing when people don't even consider if their interviewers/testers are on the same forums and see the questions/answers.
Hello All.
This topic is very interesting and there is a lot for me to learn.
I have a basic question, Please excuse me for my ignorance.
If the question has to be answered using data step only, can one use procs's for example proc means or proc sql ?
I think the problem SHOULD be answered by PROC SUMMARY/PROC MEANS or PROC SQL. I don't think people should program their own sums or means or other basic statistics by group in a DATA step. We have seen, in the SAS Communities, over and over again, people (usually with just a little experience in SAS) struggle to do this in a DATA step, and get it wrong, or they write code that doesn't work, or they write code that mis-handles missing values. Why spend the time writing DATA step code, debugging it, verifying it works, when SAS has already done this in PROC SUMMARY (and it works properly with missing values)???
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.