BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I use the following column statement in proc report

column varname
(%do zz=1 %to &mcount; &&mname&zz %end;);;

&&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.
3 REPLIES 3
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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;
WHERE YEAR() = YEAR(TODAY());

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
http://support.sas.com/documentation/cdl/en/basess/58133/HTML/default/a001304321.htm
ChrisNZ
Tourmaline | Level 20
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:
[pre]
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;
run;
quit;
[/pre]
If you force the column name in the column statement, then that column will be shown.
deleted_user
Not applicable
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

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
  • 3 replies
  • 603 views
  • 0 likes
  • 3 in conversation