Deusdeorum
Deusdeorum

Reputation: 1426

Creating a dummy variable from a string variable

I'd like to create a dummy variable from a string variable (Q1) with different comments in it with syntax. If Q1 is empty paste a zero into Q1_d and if Q1 has text inside it paste one into Q1_d.

Upvotes: 3

Views: 314

Answers (1)

Jignesh Sutar
Jignesh Sutar

Reputation: 2929

COMPUTE Q1_d=LENGTH(Q1)>0. 

Which will create dichotomous 0/1 variable Q1_d. If row case data at Q1 has data/characters then a 1 (one) will be assigned at Q1_d else if Q1 equals an empty string then 0 (zero) will be assigned.

Upvotes: 2

Related Questions