Help using Base SAS procedures

proc report making use of a by variable

Not applicable
Posts: 0

proc report making use of a by variable

I use the following column statement in proc report

column varname
(%do zz=1 %to &mcount; &&mname&zz %endSmiley Wink;;

&&mname&zz contains the text for each month and year in the dataset

I now want to break up the report by year so I've added a by year to the proc report.

How can I test that the column name contains the correct year? When I add the by statement I get lots of blank columns. For example, march2009 is blank when the by value is 2008.
Super Contributor
Super Contributor
Posts: 3,176

Re: proc report making use of a by variable

Posted in reply to deleted_user
You can use the WHERE statement to control you rinput file selection with PROC REPORT.

You will be better off sharing your SAS code, because it is unclear what SAS CHARACTER or NUMERIC variable(s) you have that are being used.

For your own convenience, consider having a SAS DATE (NUMERIC type) variable in your input file (maybe you already have this?) and use it in your WHERE statement, such as:

* select input observations only for current year;

The alternative if you only have a text-format month/year is to attempt to parse out the year-portion and use it in a WHERE statement.

Some suggested reading on SAS DATE variables pasted below.

Scott Barry
SBBWorks, Inc.

Step-by-Step Programming with Base SAS(R) Software
Working with Dates in the SAS System
Posts: 2,344

Re: proc report making use of a by variable

Posted in reply to deleted_user
Have you tried reorganising your data to use
[pre]define month /across[/pre]
so that the values of
[pre]column &&mname&zz [/pre]
now come from one variable ?

There is no girl aged 16, and the column 16 does not appear for girls in:
proc sort data=SASHELP.CLASS out=CLASS;
by SEX;
proc report data=CLASS nowd;
define AGE /across;
define WEIGHT /mean;
column AGE,WEIGHT;
by SEX;
If you force the column name in the column statement, then that column will be shown.
Not applicable
Posts: 0

Re: proc report making use of a by variable

To get it to work I had to create a macro variable

call symput('mmm' || left(cnt), '_C'||compress(monthnum+1)||'_');

where monthnum is the number 1 through 12 of each month. To this I had to add one so in the compute I could refer to the column number
Ask a Question
Discussion stats
  • 3 replies
  • 3 in conversation