Help using Base SAS procedures

Proc Report: Across variable names in Out= dataset

Reply
New Contributor
Posts: 4

Proc Report: Across variable names in Out= dataset

I am using Proc Report with an ACROSS variable to create a new dataset in the OUT= option. However, the variables in the new dataset that were created by the across variable do not have meaninful names.

How can I make the new variable names = the value of the ACROSS variable?

PROC REPORT DATA = INITIAL_DATANOWD OUT=NEW_DATA;
COLUMN ID MONTH,BALANCE;
DEFINE ID /GROUP ;
DEFINE MONTH /ACROSS ;
DEFINE BALANCE /SUM;
RUN;

New_data has variables:
Name = "_C2_", Label = MONTH
Name = "_C3_", Label = MONTH
Name = "_C4_", Label = MONTH
...Etc


Whereas I want New_data to have variables:
Name = "JAN"
Name = "FEB"
Name = "MAR"
Super Contributor
Super Contributor
Posts: 3,174

Re: Proc Report: Across variable names in Out= dataset

Have you considered PROC TRANSPOSE (using ID and IDLABEL statements) after using PROC SUMMARY, instead?

I do know of a SAS format MONNAME3. which will display the three-character Month abbreviation, when referencing a SAS DATE type (numeric) variable. Not sure if it would be suitable for your PROC REPORT code though.

Scott Barry
SBBWorks, Inc.
SAS Super FREQ
Posts: 8,864

Re: Proc Report: Across variable names in Out= dataset

Hi:
As Scott suggests, if all you need is an output dataset, you may want to use different techniques. If you want to stick with a PROC REPORT technique, however, then your choice is to use the RENAME= option on the OUT= specification, as shown in the code below.

PROC REPORT assigns absolute column numbers and only absolute column numbers to the variables it creates from ACROSS variable values -- so, you have to control the names if you do not want the absolute column numbers.

cynthia
[pre]
proc report data=sashelp.shoes nowd
out=work.shoeout(rename=(_c2_=Asia _c3_=Canada _c4_=Pacific));
where region in ('Asia', 'Canada', 'Pacific');
column product region,sales;
define product / group;
define region / across;
define sales/sum;
run;

ods listing;
proc print data=shoeout;
run;
[/pre]
Ask a Question
Discussion stats
  • 2 replies
  • 169 views
  • 0 likes
  • 3 in conversation