Hi there,
I have data in format similar to the following but with many more columns of "Codes" (Code_01 to Code_20) and corresponding "Indicators" (Indicator_01 to Indicator_20):
| ID | Name | Age | Code_01 | Code_02 | Code_03 | Indicator_01 | Indicator_02 | Indicator_03 |
| 001 | John | 42 | AAA | BBB | CCC | No | No | Yes |
| 002 | Kathy | 83 | DDD | EEE | FFF | No | No | No |
| 003 | Joe | 83 | GGG | HHH | III | No | Yes | No |
And need to convert it into something like the following:
| ID | Name | Age | Code | Indicator |
| 001 | John | 42 | AAA | No |
| 001 | John | 42 | BBB | No |
| 001 | John | 42 | CCC | Yes |
| 002 | Kathy | 83 | DDD | No |
| 002 | Kathy | 83 | EEE | No |
| 002 | Kathy | 83 | FFF | No |
| 003 | Joe | 83 | GGG | No |
| 003 | Joe | 83 | HHH | Yes |
| 003 | Joe | 83 | III | No |
Is there an efficient way to do that?
Thanks.
Jason
If it is just those two variables it is pretty easy to do with arrays.
data want ;
set have;
array _code code_01-code_20;
array _ind indicator_01-indicator_20;
do index=1 to dim(_code);
Code = _code[index];
Indicator = _ind[index];
output;
end;
drop code_01-code_20 indicator_01-indicator_20;
run;
If it is just those two variables it is pretty easy to do with arrays.
data want ;
set have;
array _code code_01-code_20;
array _ind indicator_01-indicator_20;
do index=1 to dim(_code);
Code = _code[index];
Indicator = _ind[index];
output;
end;
drop code_01-code_20 indicator_01-indicator_20;
run;
Great thanks!
There's the %UNTRANSPOSE macro at https://support.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2018/2419-2018.pdf
The example on page 2 seems exactly the same type of operation as you are asking about.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.