BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AdityaKir
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

4 REPLIES 4
Reeza
Super User

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. 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

AdityaKir
Fluorite | Level 6

Thanks for the help.

LinusH
Tourmaline | Level 20
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

CFC_SAS_Communities_400x225.jpg

Call for content now open!

It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.

Submit your proposal →

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
  • 4 replies
  • 3977 views
  • 3 likes
  • 4 in conversation