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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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