I have the following data. The real data is about 100 columns
data have; input id$ cause1$ cause2$ cause3$ effect1$ effect2$ effect3$ @@@@@@@; datalines; aa 001 001 002 001 003 . bb 005 . . 004 005 001 cc 001 003 002 001 003 002 dd 002 004 009 002 005 006 ; run;
The codes aren't very helpful for analysis. So I'd like to add a character to the start based on the header.
VNAME function within an array.
data want;
set have;
array _vars(*) cause1--effect3;
do i=1 to dim(_vars);
_vars(i) = catt(substr(vname(_vars), 1, 1), _vars(i));
end;
run;
@cobba wrote:
I have the following data. The real data is about 100 columns
data have; input id$ cause1$ cause2$ cause3$ effect1$ effect2$ effect3$ @@@@@@@; datalines; aa 001 001 002 001 003 . bb 005 . . 004 005 001 cc 001 003 002 001 003 002 dd 002 004 009 002 005 006 ; run;The codes aren't very helpful for analysis. So I'd like to add a character to the start based on the header.
VNAME function within an array.
data want;
set have;
array _vars(*) cause1--effect3;
do i=1 to dim(_vars);
_vars(i) = catt(substr(vname(_vars), 1, 1), _vars(i));
end;
run;
@cobba wrote:
I have the following data. The real data is about 100 columns
data have; input id$ cause1$ cause2$ cause3$ effect1$ effect2$ effect3$ @@@@@@@; datalines; aa 001 001 002 001 003 . bb 005 . . 004 005 001 cc 001 003 002 001 003 002 dd 002 004 009 002 005 006 ; run;The codes aren't very helpful for analysis. So I'd like to add a character to the start based on the header.
Replace line:
_vars(i) = catt(substr(vname(_vars), 1, 1), _vars(i));
into:
_vars(i) = catt(substr(vname(_vars(i)), 1, 1), _vars(i));
Replace the IF with this:
Accounts for missing and I had missed the (i) in the array reference within the VNAME() function.
if not missing(_vars(i)) then _vars(i) = catt(substr(vname(_vars(i)), 1, 1), _vars(i));
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.