BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tainaj
Obsidian | Level 7

I am trying to do a two-way table between edu_14 (education level) and D_biep_White_Good_all  (IAT score), but I want to condense the amount of education levels currently under edu_14 into 3 groups. I tried using If Then statements, but it still shows 14 levels of education instead of the 3 that I tried to create. Does anyone know what I could do to accomplish this? Please let me know if you require further information.

 

SAS code:

proc import out=work.IAT2020_raw
datafile="C:\Users\tjoseph6\Documents\My SAS Files\IAT2020.sav"
dbms=sav replace;
run;
Proc format;
value D_biep_White_Good_all -207921386783994-<-0.65='Strong Pro-Black'
-0.649989887175-<-0.35='Moderate Pro-Black'
-0.34999554285916-<-0.15='Slight Pro-Black'
-0.14999854985332-0.14999827213744='Little to No Bias'
0.15-0.34999930082848='Slight Pro-White'
0.35-0.64999802936042='Moderate Pro-White'
0.65-2='Strong Pro-White';
data Edu2020;
set work.IAT2020_raw (keep=D_biep_White_Good_all edu_14);
if D_biep_White_Good_all eq "." then delete;
if edu_14 eq 2 & 3 & 4 then Education='High School student or High School degree';
else if edu_14 eq 5 & 6 & 7 then Education='College degree';
else if edu_14 eq 8 & 9 & 10 & 11 & 12 & 13 & 14 then Education='Postgraduate or Professional Degree';
run;
proc freq data=Edu2020;
tables edu_14*D_biep_White_Good_all;
format D_biep_White_Good_all D_biep_White_Good_all.;
run;
proc reg data=Edu2020;
model D_biep_White_Good_all=edu_14;
run;

 

Log:

288 proc import out=work.IAT2020_raw
289 datafile="C:\Users\tjoseph6\Documents\My SAS Files\IAT2020.sav"
290 dbms=sav replace;
291 run;

NOTE: Variable Name Change. D_biep.White_Good_all -> D_biep_White_Good_all
NOTE: Variable Name Change. D_biep.White_Good_36 -> D_biep_White_Good_36
NOTE: Variable Name Change. D_biep.White_Good_47 -> D_biep_White_Good_47
NOTE: One or more variables were converted because the data type is not supported by the V9 engine.
For more details, run with options MSGLEVEL=I.
NOTE: The import data set has 1757576 observations and 505 variables.
NOTE: WORK.IAT2020_RAW data set was successfully created.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 1:22.45
cpu time 18.31 seconds


292 Proc format;
293 value D_biep_White_Good_all -207921386783994-<-0.65='Strong Pro-Black'
294 -0.649989887175-<-0.35='Moderate Pro-Black'
295 -0.34999554285916-<-0.15='Slight Pro-Black'
296 -0.14999854985332-0.14999827213744='Little to No Bias'
297 0.15-0.34999930082848='Slight Pro-White'
298 0.35-0.64999802936042='Moderate Pro-White'
299 0.65-2='Strong Pro-White';
NOTE: Format D_BIEP_WHITE_GOOD_ALL is already on the library WORK.FORMATS.
NOTE: Format D_BIEP_WHITE_GOOD_ALL has been output.

NOTE: PROCEDURE FORMAT used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds


300 data Edu2020;
301 set work.IAT2020_raw (keep=D_biep_White_Good_all edu_14);
302 if D_biep_White_Good_all eq "." then delete;
303 if edu_14 eq 2 & 3 & 4 then Education='High School student or High School degree';
304 else if edu_14 eq 5 & 6 & 7 then Education='College degree';
305 else if edu_14 eq 8 & 9 & 10 & 11 & 12 & 13 & 14 then Education='Postgraduate or Professional
305! Degree';
306 run;

NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
302:29
NOTE: There were 1757576 observations read from the data set WORK.IAT2020_RAW.
NOTE: The data set WORK.EDU2020 has 1213012 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 38.10 seconds
cpu time 2.28 seconds


307 proc freq data=Edu2020;
308 tables edu_14*D_biep_White_Good_all;
309 format D_biep_White_Good_all D_biep_White_Good_all.;
310 run;

NOTE: There were 1213012 observations read from the data set WORK.EDU2020.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.80 seconds
cpu time 0.57 seconds


311 proc reg data=Edu2020;
312 model D_biep_White_Good_all=edu_14;
313 run;

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

You have logic error:

if edu_14 eq 2 & 3 & 4 then Education='High School student or High School degree';
else if edu_14 eq 5 & 6 & 7 then Education='College degree';
else if edu_14 eq 8 & 9 & 10 & 11 & 12 & 13 & 14 then Education='Postgraduate or Professional Degree';

In all three statements edu_14 is compared with the first number after "eq" but not with the other numbers you have listed. To compare one variable with multiple values, you have to use the in-operator:

if edu_14 in (2, 3, 4) then ....

Using a format in the reporting procedure is the recommended way.

Another problem: you don't use the variable "Education" in the analysis steps.

You want to post data in usable form, so that some could suggest working code.

View solution in original post

3 REPLIES 3
andreas_lds
Jade | Level 19

You have logic error:

if edu_14 eq 2 & 3 & 4 then Education='High School student or High School degree';
else if edu_14 eq 5 & 6 & 7 then Education='College degree';
else if edu_14 eq 8 & 9 & 10 & 11 & 12 & 13 & 14 then Education='Postgraduate or Professional Degree';

In all three statements edu_14 is compared with the first number after "eq" but not with the other numbers you have listed. To compare one variable with multiple values, you have to use the in-operator:

if edu_14 in (2, 3, 4) then ....

Using a format in the reporting procedure is the recommended way.

Another problem: you don't use the variable "Education" in the analysis steps.

You want to post data in usable form, so that some could suggest working code.

Kurt_Bremser
Super User
NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column).
302:29

points to

302 if D_biep_White_Good_all eq "." then delete;

which means that the variable is numeric.

Replace this statement with

if D_biep_White_Good_all ne .;

which is a Subsetting IF.

 

Usable example data will greatly speed up the process of finding a solution. Either use a DATA step with DATALINES, or give us a link from which we can download the data (if publicly available).

tainaj
Obsidian | Level 7

I know I already found the solution for my initial issue, but I do appreciate you pointing this out as well. Here is the link to the data: https://osf.io/dk8p4/, and the name is "Race.IAT.public.2020.sav". The codebook can also be found there as well. It is extremely large which is why I didn't include it initially. Also, this isn't all of my code as I am working with multiple variables, but this specific two-table was the only issue I was having so I condensed it and put it under a different data name to ask this question to avoid messing with my original data I'm working on if that makes sense.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1120 views
  • 3 likes
  • 3 in conversation