When you have a table like;
somefield1 somefield2 lastterm1 lastterm2
(10) (20) (1) (-)
(20) (40) (1) (2)
(30) (50) (-) (2)
and try to group for each term, is there an easier way to do it rather than;
PROC SQL;
CREATE TABLE WORK.LAST_TERM1 AS
SELECT T1.LASTTERM1,
(MEAN(t1.'somefield1'n)) FORMAT=COMMAX14.2 AS 'MEAN_of_somefield1'n,
(MEAN(t1.'somefield2'n)) FORMAT=COMMAX14.2 AS 'MEAN_of_somefield2'n
FROM WORK.MAIN_TABLE t1
GROUP BY t1.LASTTERM1;
RUN;
PROC SQL;
CREATE TABLE WORK.LAST_TERM2 AS
SELECT T1.LASTTERM2,
(MEAN(t1.'somefield1'n)) FORMAT=COMMAX14.2 AS 'MEAN_of_somefield1'n,
(MEAN(t1.'somefield2'n)) FORMAT=COMMAX14.2 AS 'MEAN_of_somefield2'n
FROM WORK.MAIN_TABLE t1
GROUP BY t1.LASTTERM2;
RUN;
It's not a problem with two fields and two terms, but when you have 20 terms and 200 fields this code is not effective.
I tried and failed to do something like for 1 to 20 do this and create all tables.
Is there any way to do this?