Quartz | Level 8

## Coding help

Dear Members,

Input Data: Here we have different systems (not only three, but it is also more than that), per system code we have some data in terms of GB with different dates. I have to calculate total "Size" for each "system" per month (assume here data is for Dec only).

 Date System Size 31/12/2022 CXV 158,9 Gb 31/12/2022 LZ0 947 Gb 31/12/2022 QZ0 14,68 Gb 30/12/2022 CXV 158,7 Gb 30/12/2022 LZ0 946,9 Gb 30/12/2022 QZ0 14,68 Gb 29/12/2022 CXV 158,4 Gb 29/12/2022 LZ0 946,9 Gb 29/12/2022 QZ0 14,68 Gb 28/12/2022 CXV 158,1 Gb 28/12/2022 LZ0 946,8 Gb 28/12/2022 QZ0 14,68 Gb

Output:

 Date System Size Dec CXV 634.1 Gb Dec LZ0 3787.6 GB Dec QZ0 58.72 GB
1 ACCEPTED SOLUTION

Accepted Solutions
Super User

## Re: Coding help

Assuming SIZE is a numeric variable (and not the text strings you have been displaying) just use PROC SUMMARY (also known as PROC MEANS).  If the data is already sorted use BY statement, Otherwise you can use a CLASS statement and PROC SUMMARY will group the unsorted data for you.

``````proc summary data=have nway ;
class date system ;
var size ;
format date yymmd7.;
output out=want sum= ;
run;``````
6 REPLIES 6
Super User

## Re: Coding help

Assuming that your dates are SAS date values, this will do it:

``````proc means data=have nway;
format date yymmd7.;
class date system;
var size;
output out=want sum()=;
run;``````

For working, tested code, always supply example data in a data step with datalines.

PROC Star

## Re: Coding help

First, consider whether the result you are asking for is a wise thing. Do you really want the output to include the month but not the year?

It looks like you are starting with text that has not yet been read into a SAS data set. In that case, the more difficult step is preparing the data. For example, the dates need to become true SAS dates (not characters). And size needs to be converted to a number. Does that sound about right?

At any rate, once you confirm what data we are starting with, reading it in properly is the hard part. There are dozens of people here who can show you how to summarize it.
Lapis Lazuli | Level 10

## Re: Coding help

Is the sum over certain points a reasonable measure for "size"?
And if your time series does expand over more than a month ... how would you like to have the resulting sum split up then? Per Month? ... and if the year changes in between?

Quartz | Level 8

## Re: Coding help

@fja I am not worried about year as of now, as month wise data already I have. I just need to filter data of different system and sum the size. So, If I have a way to do the same for one month , I can do it for another month.

Note: Also, it;s not mandatory to write output like this, I would be okay with as follows as well.
System Size
CXV 634.1 Gb
LZ0 3787.6 GB
QZ0 58.72 GB
Super User

## Re: Coding help

Assuming SIZE is a numeric variable (and not the text strings you have been displaying) just use PROC SUMMARY (also known as PROC MEANS).  If the data is already sorted use BY statement, Otherwise you can use a CLASS statement and PROC SUMMARY will group the unsorted data for you.

``````proc summary data=have nway ;
class date system ;
var size ;
format date yymmd7.;
output out=want sum= ;
run;``````
Lapis Lazuli | Level 10

## Re: Coding help

@Tom wrote:

... just use PROC SUMMARY (also known as PROC MEANS).  If the data is already sorted use BY statement, Otherwise you can use a CLASS statement and PROC SUMMARY will group the unsorted data for you.

Jupp ... as in Kurt's posting, i guess the two of you had the same thought.

@kumarsandip975 : That should be it, should it not?

Discussion stats
• 6 replies
• 518 views
• 2 likes
• 5 in conversation