Calcite | Level 5

## I get an error "Variable MALE is uninitialized."

This is the problem I have.

`Data data_0;	Input sex\$	race\$;	cards;Male 	WhiteMale 	BlackMale 	WhiteMale 	BlackFemale	WhiteFemale	BlackFemale 	WhiteFemale 	WhiteFemale	.	 Male	.	 .  		White.  		Black; RUN;  DATA DATA_0; SET DATA_0; 	IF SEX = MALE AND RACE = WHITE THEN SEX_RACE = "MALE WHITE";	ELSE IF sex = MALE AND RACE = BLACK THEN SEX_RACE = "MALE BLACK";	ELSE IF sex = FeMALE AND RACE = BLACK THEN SEX_RACE = "FEMALE BLACK";	/*ELSE IF BMI >= 25 THEN BMI_CAT = "OVERWEIGHT";	IF BMI = . THEN BMI_CAT = " "; */ RUN;`
```Data data_0;
Input sex\$	race\$;
cards;
Male 	White
Male 	Black
Male 	White
Male 	Black
Female	White
Female	Black
Female 	White
Female 	White
Female	.
Male	.
.  		White
.  		Black
;

RUN;

DATA DATA_0;
SET DATA_0;

IF SEX = MALE AND RACE = WHITE THEN SEX_RACE = "MALE WHITE";
ELSE IF sex = MALE AND RACE = BLACK THEN SEX_RACE = "MALE BLACK";
ELSE IF sex = FeMALE AND RACE = BLACK THEN SEX_RACE = "FEMALE BLACK";

RUN;```

I get the following error!

```
1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
68
69         Data data_0;
70         Input sex\$race\$;
71
72         cards;

NOTE: SAS went to a new line when INPUT statement reached past the end of a line.
NOTE: The data set WORK.DATA_0 has 10 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time           0.00 seconds
user cpu time       0.00 seconds
system cpu time     0.00 seconds
memory              667.46k
OS Memory           23460.00k
Timestamp           10/16/2021 07:13:31 PM
Step Count                        24  Switch Count  2
Page Faults                       0
Page Reclaims                     149
Page Swaps                        0
Voluntary Context Switches        10
Involuntary Context Switches      0
Block Input Operations            0
Block Output Operations           264

85         ;
86
87          RUN;
88
89          DATA DATA_0;
90          SET DATA_0;
91
92          IF SEX = MALE AND RACE = WHITE THEN SEX_RACE = "MALE WHITE";
93         ELSE IF sex = MALE AND RACE = BLACK THEN SEX_RACE = "MALE BLACK";
94         ELSE IF sex = FeMALE AND RACE = BLACK THEN SEX_RACE = "FEMALE BLACK";
95
96         /*ELSE IF BMI >= 25 THEN BMI_CAT = "OVERWEIGHT";
97         IF BMI = . THEN BMI_CAT = " "; */
98          RUN;

NOTE: Variable MALE is uninitialized.
NOTE: Variable WHITE is uninitialized.
NOTE: Variable BLACK is uninitialized.
NOTE: Variable FeMALE is uninitialized.
NOTE: There were 10 observations read from the data set WORK.DATA_0.
NOTE: The data set WORK.DATA_0 has 10 observations and 7 variables.
NOTE: DATA statement used (Total process time):
real time           0.00 seconds
user cpu time       0.00 seconds
system cpu time     0.00 seconds
memory              953.96k
OS Memory           23976.00k
Timestamp           10/16/2021 07:13:31 PM
Step Count                        25  Switch Count  2
Page Faults                       0
Page Reclaims                     164
Page Swaps                        0
Voluntary Context Switches        11
Involuntary Context Switches      0
Block Input Operations            0
Block Output Operations           264

99
100        OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
110        ```

Can someone help me?

5 REPLIES 5
PROC Star

## Re: I get an error "Variable MALE is uninitialized."

When you refer to the value of a character variable, you have to put it in quotes:

``if sex='Male' then ......``

Other notes:

• Case is important.  This would fail:  if sex="MALE' then ......
• You probably typed in tabs as part of the data, instead of spaces.  If so, you would need to replace the tab characters with spaces.

Tabs are OK in the programming statements, but not in the data.

Tourmaline | Level 20

## Re: I get an error "Variable MALE is uninitialized."

Tabs have nothing to do in a program imho. Spaces only belong in code.

Community Manager

## Re: I get an error "Variable MALE is uninitialized."

@ChrisNZ My favorite depiction of this:

SAS Hackathon registration is open! Build your skills. Make connections. Enjoy creative freedom. Maybe change the world.
Tourmaline | Level 20

## Re: I get an error "Variable MALE is uninitialized."

Lol

Glad we are on the same page and sanity prevails! 😄

Calcite | Level 5

## Re: I get an error "Variable MALE is uninitialized."

Thank you Astounding! you are right! I should have put all the values under inverted commas. Moreover, male and female, black and white should be in lower case as in the data.
Discussion stats
• 5 replies
• 1617 views
• 7 likes
• 4 in conversation