BookmarkSubscribeRSS Feed
tekish
Quartz | Level 8

 

 

I have  report with more than 200 columns and I want to create a macro column names.

 

here is the sample codes:

 

data class;

set sashelp.class;

nodeid100="";nodeid101="";nodeid102="";nodeid103="";nodeid104="";nodeid105="";nodeid106="";nodeid107="";

nodeid108="";nodeid109="";nodeid110="";nodeid111="";nodeid112="";nodeid113="";nodeid114="";nodeid115="";

run;

ods excel file="\test.xlsx";

proc report data=class;

column name substr(nodeid136,7);

run;

ods _all_ close;

 

my expected output would be:

Name100101102103104105106107108109110111112113114115
Alfred                
Alice                
Barbara                
Carol                
Henry                
James                
Jane                
Janet                
Jeffrey                
John                
Joyce                
Judy                
Louise                
Mary                
Philip                
Robert                
Ronald                
Thomas                
William                

 

 

4 REPLIES 4
Shmuel
Garnet | Level 18

Why are you using %substr() - it is intended to be used within a macro program.

 

try to change it into substr() (without the % symbol).

Reeza
Super User

1. What do you want in the middle? Means, maxes, etc? It does affect the data

2. It's hard to follow this, but couldn't you use labels to have the variable names appear the way you want instead? Or if the data structure doesn't lend itself to that, what about a custom format?

 

data class;
set sashelp.class;
nodeid100="";nodeid101="";nodeid102="";nodeid103="";nodeid104="";nodeid105="";nodeid106="";nodeid107="";
nodeid108="";nodeid109="";nodeid110="";nodeid111="";nodeid112="";nodeid113="";nodeid114="";nodeid115="";

label nodeid100='100' nodeid102='102' nodeid101='101';
run;

You can generate the labels using macros and SASHELP.VCOLUMN if desired. 

tekish
Quartz | Level 8

Reeza,

 

The reason I want to create a macro column is I have 200 column names to be labeled.

Reeza
Super User

It seems easier to me to create a macro to create labels. Or transpose your data and use the variable as an ACROSS variable. 

 


@tekish wrote:

Reeza,

 

The reason I want to create a macro column is I have 200 column names to be labeled.


Here's an example of how that could work. You can easily get the list of variable names from PROC CONTENTS or SASHELP.VCOLUMNS and then create the labels. 

 

Ultimately, how you choose to approach the problem is your choice. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

How to Concatenate Values

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.

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