DATA Step, Macro, Functions and more

Sum Rowwise data when the columnname is a date

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 12
Accepted Solution

Sum Rowwise data when the columnname is a date

[ Edited ]

Hello,

 

I want to know how can we sum rowwise data in SAS when the columns are dates. Below is how my Excel file looks like?

 

Dress_ID29/8/201331/8/20132/9/20134/9/20136/9/20138/9/2013
1006032852211422742491266027272887
12121920891512755707508131066
1190380701677788
966005983100511281326145515071621
87633954199611751304139614321559

 

I want to do sum row wise.

 

Regards,

 

Aditya


Accepted Solutions
Solution
‎09-23-2016 10:38 AM
Super User
Posts: 19,849

Re: Sum Rowwise data when the columnname is a date

Posted in reply to AdityaKir

Use the SUM function.

 

Sum(var1, var2, ..., varN);

 

SAS doesn't allow variable names of that type. It will transform them when imported - it would be easier if you modified them manually so you have a system you understand. 

 

If you declare an array you can 

 

array date_vars(12) date1-date12;

total=sum( of date_vars(*));

 

There are other ways to list the variables based on the convention you choose. Search VARIABLE LIST on here or in SAS documentation. 

 

View solution in original post


All Replies
Solution
‎09-23-2016 10:38 AM
Super User
Posts: 19,849

Re: Sum Rowwise data when the columnname is a date

Posted in reply to AdityaKir

Use the SUM function.

 

Sum(var1, var2, ..., varN);

 

SAS doesn't allow variable names of that type. It will transform them when imported - it would be easier if you modified them manually so you have a system you understand. 

 

If you declare an array you can 

 

array date_vars(12) date1-date12;

total=sum( of date_vars(*));

 

There are other ways to list the variables based on the convention you choose. Search VARIABLE LIST on here or in SAS documentation. 

 

Super User
Super User
Posts: 7,977

Re: Sum Rowwise data when the columnname is a date

[ Edited ]
Posted in reply to AdityaKir

It is a good idea for you to import that data from Excel and show us what the dataset looks like.  That could be a picture for all I know, Excel has no structure or control so it is not possible to work from that point.  Once you have a dataset, look at what the variable names are, if they are imported as varX then your problem is a very simple one:

result=sum(of var:);

If they are not, then you may have work in manipulating the data into a useable format.

Occasional Contributor
Posts: 12

Re: Sum Rowwise data when the columnname is a date

Thanks for the help.

Super User
Posts: 5,434

Re: Sum Rowwise data when the columnname is a date

Posted in reply to AdityaKir
Remember that SAS is not Excel. You'll be better off restructuring your data in a normalized way - by making a date column. Then you'll have lots possibilities to do any calculations you need. Summarization is usually a task for a report so you could use PROC PRINT if you wish to keep the details or TABULATE for aggregation only reports.
Data never sleeps
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 282 views
  • 3 likes
  • 4 in conversation