Hello! I have been trying to debug the following code, and I am having trouble in the data step. I am supposed to Create the following:
PROC IMPORT
DATAFILE='/home/u59343073/Data File PH 629 II/yrbs2017.sav'
DBMS=SAV OUT = yrbss REPLACE;
run;
DATA YRBSS;
IF Q88 IN ( 1 2 3 4 ) THEN SHORTSLEEP = 0;
ELSE IF Q88 IN ( 5 6 7 ) THEN SHORTSLEEP = 1;
IF Q88 NOT EQ .;
IF Q3 IN (10 11 12);
RUN;
I suspect you may be having an issue with this requirement:
79 IF Q3 IN (10 11 12);
The last time I was involved with YRBS data the question was not coded 10, 11, 12 but 1,2,3,4 (or one year A, B, C, D) for grades 9,10,11, 12. Amazingly enough Q3 in 2007 was the grade question as well. (For those who haven't worked with CDC sponsored surveys like this, not really amazing, some things just don't change quickly at CDC).
Since this came from an SPSS data set if you looked at that and saw the grade numbers you might be seeing the SPSS Value Labels.
You do not read anything in your DATA step, so it overwrites your existing dataset with missing values.
Create a new dataset from the imported one:
data yrbss_2;
set yrbss;
/* other code */
Thank you! I did what you recommended, however the log says there is 0 observations. This is causing trouble for the rest of my code. Attached is my log.
Please provide a complete SAS log, including the PROC IMPORT step. Use the </> menu option and copy and paste your log, don't use screenshots.
95 data yrbss_female; 96 set yrbss; 97 if sex = 1; 98 run; NOTE: Variable sex is uninitialized. NOTE: There were 14765 observations read from the data set WORK.YRBSS. NOTE: The data set WORK.YRBSS_FEMALE has 0 observations and 241 variables.
The first note tells you that there is no variable named "sex" in your dataset. It will always be missing, so the condition is always false.
74 DATA yrbss_2; 75 set yrbss; 76 IF Q88 IN (1,2,3,4) THEN SHORTSLEEP = 0; 77 ELSE IF Q88 IN ( 5 6 7 ) THEN SHORTSLEEP = 1; 78 IF Q88 NOT EQ .; 79 IF Q3 IN (10 11 12); 80 RUN; NOTE: There were 14765 observations read from the data set WORK.YRBSS. NOTE: The data set WORK.YRBSS_2 has 0 observations and 241 variables.
One or both subsetting IFs have their condition never met. Before you try to subset, run a PROC FREQ on the variables to see which values are contained.
I suspect you may be having an issue with this requirement:
79 IF Q3 IN (10 11 12);
The last time I was involved with YRBS data the question was not coded 10, 11, 12 but 1,2,3,4 (or one year A, B, C, D) for grades 9,10,11, 12. Amazingly enough Q3 in 2007 was the grade question as well. (For those who haven't worked with CDC sponsored surveys like this, not really amazing, some things just don't change quickly at CDC).
Since this came from an SPSS data set if you looked at that and saw the grade numbers you might be seeing the SPSS Value Labels.
Thank you! I did what you recommended and it worked. I am having trouble on the last step, which is subsetting the male data file to include participants that are classified as having "normal weight" according to their BMI (18.5–24.9kg/(m*m)). Attached is my whole log. When I run it, there is 0 observations.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.