BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.

Dear Members,

Please help with some calculation here.

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).

DateSystemSize
31/12/2022CXV158,9 Gb
31/12/2022LZ0947 Gb
31/12/2022QZ014,68 Gb
30/12/2022CXV158,7 Gb
30/12/2022LZ0946,9 Gb
30/12/2022QZ014,68 Gb
29/12/2022CXV158,4 Gb
29/12/2022LZ0946,9 Gb
29/12/2022QZ014,68 Gb
28/12/2022CXV158,1 Gb
28/12/2022LZ0946,8 Gb
28/12/2022QZ014,68 Gb

 

Output:

DateSystemSize
DecCXV634.1 Gb
DecLZ03787.6 GB
DecQZ058.72 GB
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

6 REPLIES 6
Kurt_Bremser
Super User

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.

Astounding
PROC Star
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.
fja
Lapis Lazuli | Level 10 fja
Lapis Lazuli | Level 10

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?

kumarsandip975
Quartz | Level 8
@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
Tom
Super User Tom
Super User

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;
fja
Lapis Lazuli | Level 10 fja
Lapis Lazuli | Level 10

@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?

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 6 replies
  • 499 views
  • 2 likes
  • 5 in conversation