So I have a variable in my datasheet named 'Symptoms', and in my questionnaire, the question associated to this variable gave the participants a list of symptoms and asked them to choose the ones they had experienced (multiple selections were allowed)and as far as scoring is concerned, the number of symptoms selected by each user would give me their score for that question. Anyway after importing my data to SPSS, this variable has been turned into a string consisting of all the symptoms selected by
On Friday, September 4, 2020 at 3:55:52 PM UTC-4, Farnood Saghi wrote:and as far as scoring is concerned, the number of symptoms selected by each user would give me their score for that question. Anyway after importing my data to SPSS, this variable has been turned into a string consisting of all the symptoms selected by
So I have a variable in my datasheet named 'Symptoms', and in my questionnaire, the question associated to this variable gave the participants a list of symptoms and asked them to choose the ones they had experienced (multiple selections were allowed)
There might be a Python function to count the number of commas in a string. But here's an old fashioned NPR (no Python required) approach that works on a toy dataset I made up.
NEW FILE.
DATASET CLOSE ALL.
DATA LIST LIST / Symptoms (A150).
BEGIN DATA
"fever, dry cough, fatigue"
"aches and pains, sore throat, diarrhoea, conjunctivitis"
"headache"
"loss of taste or smell, skin rash, discolouration of fingers or toes, difficulty breathing or shortness of breath"
""
"chest pain or pressure, loss of speech or movement"
END DATA.
* Let scratch variable #L = length of string variable Symptoms.
COMPUTE #L = CHAR.LENGTH(Symptoms).
* Set N to 0 or 1 initially.
COMPUTE N = #L GT 0.
LOOP # = 1 to 500.
COMPUTE N = SUM(N, CHAR.SUBSTR(Symptoms,#,1) EQ ",").
END LOOP IF # GT #L.
FORMATS N (F2.0).
VARIABLE LABELS N "Number of symptoms".
LIST.
OUTPUT from LIST:
The variables are listed in the following order:
LINE 1: Symptoms
LINE 2: N
Symptoms: fever, dry cough, fatigue
N: 3
Symptoms: aches and pains, sore throat, diarrhoea, conjunctivitis
N: 4
Symptoms: headache
N: 1
Symptoms: loss of taste or smell, skin rash, discolouration of fingers or toes, difficulty breathing or shortness of breath
N: 4
Symptoms:
N: 0
Symptoms: chest pain or pressure, loss of speech or movement
N: 2
Number of cases read: 6 Number of cases listed: 6
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (3 / 13) |
Uptime: | 58:49:31 |
Calls: | 6,653 |
Calls today: | 5 |
Files: | 12,200 |
Messages: | 5,331,149 |