Hi,
I have this dummy code (only a section as this goes up to December) below where I have sum for each variable. How do I group this into one variable so my next part of code referencing the table will look at variable 'x' instead of having to type out each individual variable name again?
I basically want
sum(jancount) as onecount,
sum(janvalue) as onevalue,
sum(febcount) as twocount,
sum(febvalue) as twovalue,
sum(marcount) as threecount,
sum(marvalue) as threevalue as all_data
I hope that makes sense.
proc sql;
create table test.test_cas as
select
pydate,
sum(jancount) as onecount,
sum(janvalue) as onevalue,
sum(febcount) as twocount,
sum(febvalue) as twovalue,
sum(marcount) as threecount,
sum(marvalue) as threevalue
from test.testing
group by pydate;
Your making it difficult for yourself. It is never a good idea to put data observations in colums - i.e. rather than this:
jancount janvalue febcount febvalue
Which is very hard to program with, and not good data storage (what happens at end of year, overlaps etc.
A simpler, better solution:
Date Count Value
With this you can simply summarise the data using proc means/summary. The date value can be formatted as month, but would be expandable across years, sub dividable out and generally far more usable. Just your code you present there, having to type in manually each variable name is a real pain, SQL is designed to work with normalised data (as I showed), not transposed, and even SAS which has some shortcuts doesn't work that great with transposed data.
The data is already set out that way in production (I just sent dummy data across) and I want to create a tabulate on the back of the data but there will be too many dimensions (unless I am doing the tabulate wrong).
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.