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));
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.