BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DingDing
Quartz | Level 8

I need to change something with all the variables in my dataset, but there are around 100 variables and at the same time, the column names are very different and irregular , for example, ws  tsfg  ttt  etttt ssdf  tkw  trp.

 

Of course I can't do the same behavior for each variable for 100 times. I am wondering is there an efficient way to do with the irregular variable names?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

If your recoding or doing some sort of calculation you can also use arrays and short references such as 

 

Array var_list(*) first_var -- last_var ;

 

this will include all variables from first to last based on variable portion. 

View solution in original post

3 REPLIES 3
Reeza
Super User

Yes ... But it depends on what you want to do. Common tasks are adding a prefix or suffix, renaming based on lookup table, or adding labels. 

 

Many of these can be automated by leveraging some basic macro variables and using sashelp.vcolumn/dictionary.column table. 

If you've never used the dictionary tables navigate to the sashelp library and take a look at .vtable vcolumn tables which have metadata about all your SAS datasets. 

 

 

Reeza
Super User

If your recoding or doing some sort of calculation you can also use arrays and short references such as 

 

Array var_list(*) first_var -- last_var ;

 

this will include all variables from first to last based on variable portion. 

PGStats
Opal | Level 21

Assuming you have a list of name equivalents, transform that list into a macro variable which can be inserted in a rename statement:

 

data names;
length oldName newName $32;
input oldName newName;
datalines;
weight kilos
height inches
age years
name firstName
sex gender
;

proc sql;
select catx("=", oldName, newName) into : rename separated by " "
from names;
quit;

data myClass;
set sashelp.class;
rename &rename;
run;

proc contents data=myClass; run;
PG

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!

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
  • 3 replies
  • 1715 views
  • 2 likes
  • 3 in conversation