For example below
Peter 2 14 16
James 3 17 19 18
Max 1 7
Logan 5 19 15 11 9 18
…
…
First variable is Name, Second variable is number of visit and others are amounts.
Peter visited twice so there are 2 amount variables and James visited three times so there are 3 amount variables.
Is it possible to just ignore reading Amount variables and just calculate sum of amount variables for each person and running total of the total amount variables for each person in a single data step?
Result should be like this.
Name TotalAmt Runtotal
Peter 30 30
James 54 84
Max 7 91
Logan 72 163
...
...
assuming you have variables named AMOUNT1-AMOUNT5
Use
totalamt=sum(of amount1-amount5);
runtotal+totalamt;
What if you don't know how many variables are in the data?
I mean in the datalines, there are random number of amount variables. (You don't know the maximum number of Amount Variable)
Datalines above is just an example in a whole datalines
Surely you must have a SAS data set. PROC CONTENTS will tell you what variables exist, you can use that information.
Please show us an actual SAS data set, following these instructions: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.