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

Hello,

I have a data set with a dynamic number of columns. This means the count of the columns is growing every trimester by 1.

Now I should be able to add a additional line which is calculating the total (sum).

Does anybody have an idea?

The set looks like the following:

X_Class12012/12012/22012/32012/4
15006003001000
2400550250850
3100200110620

Now I should generate a line X_Class1:9999 with the totals of each column in it.

In addition at the 4/1/13 an new column 2013/1 will be added and the total must also be generatet automatically in there.

thank you

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

My earlier solution should give you exactly the numbers you asked for.  It won't say "Total" because that wasn't part of the original problem, but that's easy to accomplish by making three changes:

where X_Class1 ne 'Total';

(where=(X_Class1 ne 'Total'))

X_Class1='Total';

Notice that ne : has become ne.  If  you're getting output that is not what you want, post what changes you would like to see.

Good luck.

View solution in original post

5 REPLIES 5
data_null__
Jade | Level 19

In your SAS data set name the dynamic colums with a common root.  QTR2012_1 QTR2012_2 etc.

Then you can use a "SAS Variable List" such as QTR: to refer to all the variables in a consise way.

TOTAL=sum(OF qtr:);  The keyword OF is important for use in the function.

http://support.sas.com/documentation/cdl/en/lrcon/65287/HTML/default/viewer.htm#p0wphcpsfgx6o7n1sjtq...

http://support.sas.com/documentation/cdl/en/lrcon/65287/HTML/default/viewer.htm#p0wphcpsfgx6o7n1sjtq...

Astounding
PROC Star

You're leaving a lot to the imagination here.  I'll assume (as data _null_ did) that your numeric variable names all begin with QTR.  Also, I'll assume that X_Class1 is character with a length of at least 6.  Also, I'll assume your data set doesn't contain any additional variables that you haven't told us about.

Here's an approach:

proc means data=have noprint;

   var qtr:;

   where X_Class1 ne : '1:';

   output out=totals (keep=qtr:) mean=;

run;

data want;

   set have (where=(X_Class1 ne : '1:')) end=done;

   output;

   if done;

   set totals;

   X_Class1=cats('1:', _n_);

   output;

run;

Good luck.

meatmuffin
Calcite | Level 5

Thanks for the answers, but it didn't give me the result i expected.

I think I was not precisely enough. I'm sorry for that.

I try it once again.

At the moment I'm having the table as shown above by my first posting.

After summarizing the data, i would like to get the following table:

XClass_12012/12012/22012/32012/42013/1
15006003001000500
2400550250850300
3100200110620200
Total1000135066024701000

After summarizing the trimester the red line with the totals should be generated.

Thanks for the help.

Linlin
Lapis Lazuli | Level 10

data have;

input A $ B1 b2 b3 b4 b5;

data have;

input A $ B1 b2 b3 b4 b5;

cards;

1 500 600 300 1000 500

2 400 550 250 850 300

3 100 200 110 620 200

;

data want;

  set have end=last;

  output;

  t1+b1;

  t2+b2;

  t3+b3;

  t4+b4;

  t5+b5;

  if last then do;

  b1=t1; b2=t2; b3=t3;b4=t4;b5=t5;a='Total';

  output;end;

  drop t:;

  proc print noobs;run;

                            A         B1      b2      b3     b4      b5

                           1         500     600    300    1000     500

                           2         400     550    250     850     300

                           3         100     200    110     620     200

                           Total    1000    1350    660    2470    1000

Astounding
PROC Star

My earlier solution should give you exactly the numbers you asked for.  It won't say "Total" because that wasn't part of the original problem, but that's easy to accomplish by making three changes:

where X_Class1 ne 'Total';

(where=(X_Class1 ne 'Total'))

X_Class1='Total';

Notice that ne : has become ne.  If  you're getting output that is not what you want, post what changes you would like to see.

Good luck.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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