Hi everyone!!
I needed some help to find multiple variables "YEAR10_1,YEAR10_2.. so on" containing a diagnostic code string to make a new variable "Year_Diagnosis". The data looks as follows:
| ID | YEAR10_1 | YEAR10_2 | YEAR10_3 | YEAR11_1 | YEAR11_2 | YEAR12_1 | YEAR12_2 | YEAR12_3 | YEAR_DIAGNOSIS |
| 1 | C34.0 | C50.2 | C34.0 | C34.2 | 2011 | ||||
| 2 | C34.0 | C50.2 | C34.0 | C34.2 | 2010 | ||||
| 3 | C34.0 | C50.2 | C34.0 | 2012 | |||||
| 4 | C34.0 | 2010 | |||||||
| 5 | C50.2 | C34.0 | C34.0 | 2011 | |||||
| 6 | C34.0 | 2011 |
I am interested in the string starting with "C34" and the first one that appears in the column. For example, in ID=1, "C34" appears in YEAR11_1 and YEAR12_1 but I want the output diagnosis year as 2011.
I am sure there are many ways to do this but I was hoping if someone could help me find a more efficient way since I have do this many times with my data and on thousands of patients.
Thanks!!!!
Your data structure certainly ensures that performing any calculation will be a pain.
Structure your data vertically:
ID YEAR N DIAG
1 2011 1 C34.0
When you hit 2022, your program won't work anymore.
Just don't do this. The structure shown looks like a report.
Data should never be stored in this manner.
Change your table.
Hint: Column names should not contain data.
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.