I have a two string variables (DiagnosisPrimary & DiagnosisOther) that have diagnosis coded into numerical values and delineated with '~' .of numerical and text it is no longer working.
So person one was diagnosed with '20' on their first visit and then nothing on their second visit.
DiagnosisPrimary
20~
12~~~
20~20~
12~12~
12~~
~~~~~
12~12
If 20 represents having been diagnoised with depression, I want to see if there is a '20' among the string. Basically, find out who was diagnosed with dpression at any of their visits. In the past I have used the formula below, but now the data is a mix
COMPUTE Dx_Depression =ANY(20, DiagnosisPrimary) OR ANY(20, DiagnosisOther). Why not two logical comparisons where you use ANY( ) ?COMPUTE Dx_Depression=
I want to create a new variable with a true/false response.
Any help much appreicated!
This also works, however it will take far to long to run on the big data set...
COMPUTE Dx_Depression = (CHAR.INDEX(DiagnosisPrimary, '~20~') >0) or (CHAR.INDEX(DiagnosisPrimary, '~20')=char.len(DiagnosisPrimary)-3) or (CHAR.INDEX(DiagnosisPrimary, '20~')=1) or
(CHAR.INDEX(DiagnosisOther, '~20~') >0) or
(CHAR.INDEX(DiagnosisOther, '~20')=char.len(DiagnosisOther)-3) or (CHAR.INDEX(DiagnosisOther, '20~')=1).
On Thursday, February 6, 2020 at 5:02:37 PM UTC-5, erin.ps...@gmail.com wrote:
This also works, however it will take far to long to run on the big data set...
COMPUTE Dx_Depression = (CHAR.INDEX(DiagnosisPrimary, '~20~') >0) or (CHAR.INDEX(DiagnosisPrimary, '~20')=char.len(DiagnosisPrimary)-3) or (CHAR.INDEX(DiagnosisPrimary, '20~')=1) or
(CHAR.INDEX(DiagnosisOther, '~20~') >0) or
(CHAR.INDEX(DiagnosisOther, '~20')=char.len(DiagnosisOther)-3) or (CHAR.INDEX(DiagnosisOther, '20~')=1).
Does this work?
COMPUTE Dx_Depression = SUM(CHAR.INDEX(DiagnosisPrimary,'20'),CHAR.INDEX(DiagnosisOther,'20')) GT 0.
FORMATS Dx_Depression (F1).
FREQUENCIES Dx_Depression.
Or are there cases you have not shown us where '20' appears in ways that do not indicate depression. E.g., are there codes like ~201~ or ~120~ that would louse things up? If so, how about this variation on the theme?
STRING NewDx (A50).
COMPUTE NewDX = CONCAT("~",DiagnosisPrimary,"~",DiagnosisOther,"~").
COMPUTE Dx_Depression = CHAR.INDEX(NewDx, '~20~') GT 0.
FORMATS Dx_Depression (F1).
FREQUENCIES Dx_Depression.
When you are done with variable NewDx, delete it if you wish.
HTH.
On Thursday, February 6, 2020 at 5:02:37 PM UTC-5, erin.ps...@gmail.com wrote: >> This also works, however it will take far to long to run on the big data set...
COMPUTE Dx_Depression = (CHAR.INDEX(DiagnosisPrimary, '~20~') >0) or
(CHAR.INDEX(DiagnosisPrimary, '~20')=char.len(DiagnosisPrimary)-3) or
(CHAR.INDEX(DiagnosisPrimary, '20~')=1) or
(CHAR.INDEX(DiagnosisOther, '~20~') >0) or
(CHAR.INDEX(DiagnosisOther, '~20')=char.len(DiagnosisOther)-3) or
(CHAR.INDEX(DiagnosisOther, '20~')=1).
Does this work?
COMPUTE Dx_Depression = SUM(CHAR.INDEX(DiagnosisPrimary,'20'),CHAR.INDEX(DiagnosisOther,'20')) GT 0.
FORMATS Dx_Depression (F1).
FREQUENCIES Dx_Depression.
Or are there cases you have not shown us where '20' appears in ways that do not indicate depression. E.g., are there codes like ~201~ or ~120~ that would louse things up? If so, how about this variation on the theme?
STRING NewDx (A50).
COMPUTE NewDX = CONCAT("~",DiagnosisPrimary,"~",DiagnosisOther,"~").
COMPUTE Dx_Depression = CHAR.INDEX(NewDx, '~20~') GT 0.
FORMATS Dx_Depression (F1).
FREQUENCIES Dx_Depression.
When you are done with variable NewDx, delete it if you wish.
STRING NewDx (A50).
COMPUTE NewDX = CONCAT("~",DiagnosisPrimary,"~",DiagnosisOther,"~"). >COMPUTE Dx_Depression = CHAR.INDEX(NewDx, '~20~') GT 0.
FORMATS Dx_Depression (F1).
FREQUENCIES Dx_Depression.
When you are done with variable NewDx, delete it if you wish.
I like this solution because I figure that concatenating and
using one CHAR.INDEX( ) search is both easier to read and
faster to execute that doing two searches.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (2 / 14) |
Uptime: | 25:14:58 |
Calls: | 6,646 |
Calls today: | 1 |
Files: | 12,193 |
Messages: | 5,327,791 |