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?
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.
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.
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.
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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.