BookmarkSubscribeRSS Feed
PKV
Calcite | Level 5 PKV
Calcite | Level 5

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?

5 REPLIES 5
Astounding
PROC Star

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.

ChrisNZ
Tourmaline | Level 20

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

ChrisHemedinger
Community Manager

@ChrisNZ My favorite depiction of this:


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

Lol

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

PKV
Calcite | Level 5 PKV
Calcite | Level 5
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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1540 views
  • 7 likes
  • 4 in conversation