This is the problem I have.
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";
/*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?
When you refer to the value of a character variable, you have to put it in quotes:
if sex='Male' then ......
Other notes:
Tabs are OK in the programming statements, but not in the data.
Tabs have nothing to do in a program imho. Spaces only belong in code.
@ChrisNZ My favorite depiction of this:
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.