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

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:

  1. Create binary variable "shortsleep" for short sleep duration coded 0 = 7 or less hours of sleep, 1 = 8 or more hours of sleep
  2. Subset data to include only participants with nonmissing sleep data
  3. Subset data to include only participants in grades 10-12;

 

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;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

8 REPLIES 8
Kurt_Bremser
Super User

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 */

 

kmunoz16
Calcite | Level 5

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.

SASKiwi
PROC Star

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.

kmunoz16
Calcite | Level 5
My apologies. Below is my SAS log.

1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
68
69 PROC IMPORT
70 DATAFILE='/home/u59343073/Data File PH 629 II/yrbs2017.sav'
71 DBMS=SAV OUT = yrbss REPLACE;
72 run;

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 14765 observations and 240 variables.
NOTE: WORK.YRBSS data set was successfully created.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 0.13 seconds
user cpu time 0.10 seconds
system cpu time 0.03 seconds
memory 3380.00k
OS Memory 30612.00k
Timestamp 02/04/2022 06:57:28 AM
Step Count 389 Switch Count 4
Page Faults 0
Page Reclaims 540
Page Swaps 0
Voluntary Context Switches 29
Involuntary Context Switches 2
Block Input Operations 0
Block Output Operations 56064


73
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.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
user cpu time 0.02 seconds
system cpu time 0.01 seconds
memory 3191.50k
OS Memory 30376.00k
Timestamp 02/04/2022 06:57:28 AM
Step Count 390 Switch Count 5
Page Faults 0
Page Reclaims 318
Page Swaps 0
Voluntary Context Switches 17
Involuntary Context Switches 1
Block Input Operations 0
Block Output Operations 264


81
82
83 proc freq data = yrbss;
84 Tables Q2 Q3 raceeth;
85 RUN;

NOTE: There were 14765 observations read from the data set WORK.YRBSS.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.04 seconds
user cpu time 0.04 seconds
system cpu time 0.01 seconds
memory 3258.78k
OS Memory 30376.00k
Timestamp 02/04/2022 06:57:28 AM
Step Count 391 Switch Count 3
Page Faults 0
Page Reclaims 335
Page Swaps 0
Voluntary Context Switches 12
Involuntary Context Switches 1
Block Input Operations 0
Block Output Operations 272


86
87 PROC FREQ DATA = yrbss_2 (WHERE=(SHORTSLEEP=0));
88 TABLES Q2 Q3 RACEETH;
89 RUN;

NOTE: No observations in data set WORK.YRBSS_2.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 538.28k
OS Memory 29348.00k
Timestamp 02/04/2022 06:57:28 AM
Step Count 392 Switch Count 0
Page Faults 0
Page Reclaims 51
Page Swaps 0
Voluntary Context Switches 0
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 0


90
91 PROC FREQ DATA = yrbss_2;
92 TABLE Q2*SHORTSLEEP/CHISQ;
93 RUN;

NOTE: No observations in data set WORK.YRBSS_2.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 524.84k
OS Memory 29348.00k
Timestamp 02/04/2022 06:57:28 AM
Step Count 393 Switch Count 0
Page Faults 0
Page Reclaims 51
Page Swaps 0
Voluntary Context Switches 0
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 0


94
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.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
user cpu time 0.01 seconds
system cpu time 0.02 seconds
memory 2959.43k
OS Memory 30376.00k
Timestamp 02/04/2022 06:57:28 AM
Step Count 394 Switch Count 6
Page Faults 0
Page Reclaims 310
Page Swaps 0
Voluntary Context Switches 27
Involuntary Context Switches 1
Block Input Operations 0
Block Output Operations 264


99
100 data yrbss_male;
101 set yrbss;
102 if sex = 2;
103 run;

NOTE: Variable sex is uninitialized.
NOTE: There were 14765 observations read from the data set WORK.YRBSS.
NOTE: The data set WORK.YRBSS_MALE has 0 observations and 241 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
user cpu time 0.03 seconds
system cpu time 0.00 seconds
memory 2958.87k
OS Memory 30376.00k
Timestamp 02/04/2022 06:57:28 AM
Step Count 395 Switch Count 5
Page Faults 0
Page Reclaims 305
Page Swaps 0
Voluntary Context Switches 20
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 264


104
105 DATA YRBSS_MALE;
106 SET YRBSS_MALE;
107 BMI = Q7/Q6*Q6;
108 RUN;

NOTE: There were 0 observations read from the data set WORK.YRBSS_MALE.
NOTE: The data set WORK.YRBSS_MALE has 0 observations and 242 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
user cpu time 0.01 seconds
system cpu time 0.01 seconds
memory 1732.15k
OS Memory 29608.00k
Timestamp 02/04/2022 06:57:28 AM
Step Count 396 Switch Count 2
Page Faults 0
Page Reclaims 117
Page Swaps 0
Voluntary Context Switches 10
Involuntary Context Switches 1
Block Input Operations 0
Block Output Operations 264


109
110 PROC MEANS DATA = YRBSS_MALE;
111 VAR BMI;
112 RUN;

NOTE: No observations in data set WORK.YRBSS_MALE.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.00 seconds
user cpu time 0.00 seconds
system cpu time 0.00 seconds
memory 7013.56k
OS Memory 35528.00k
Timestamp 02/04/2022 06:57:28 AM
Step Count 397 Switch Count 0
Page Faults 0
Page Reclaims 1595
Page Swaps 0
Voluntary Context Switches 0
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 0


113
114 DATA YRBSS_MALE;
115 SET YRBSS;
116 if BMI<18.5 THEN DELETE;
117 else if BMI>24.9 THEN DELETE;
118 RUN;

NOTE: Variable BMI is uninitialized.
NOTE: There were 14765 observations read from the data set WORK.YRBSS.
NOTE: The data set WORK.YRBSS_MALE has 0 observations and 241 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
user cpu time 0.02 seconds
system cpu time 0.01 seconds
memory 3188.34k
OS Memory 30376.00k
Timestamp 02/04/2022 06:57:28 AM
Step Count 398 Switch Count 5
Page Faults 0
Page Reclaims 313
Page Swaps 0
Voluntary Context Switches 19
Involuntary Context Switches 1
Block Input Operations 0
Block Output Operations 264


119
120
121
122
123 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
133
Kurt_Bremser
Super User
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.

Kurt_Bremser
Super User
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.

ballardw
Super User

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.

kmunoz16
Calcite | Level 5

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.

 

OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
68
69 PROC IMPORT
70 DATAFILE='/home/u59343073/Data File PH 629 II/yrbs2017.sav'
71 DBMS=SAV OUT = yrbss REPLACE;
72 run;
 
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 14765 observations and 240 variables.
NOTE: WORK.YRBSS data set was successfully created.
NOTE: PROCEDURE IMPORT used (Total process time):
real time 0.13 seconds
user cpu time 0.10 seconds
system cpu time 0.04 seconds
memory 3264.21k
OS Memory 30100.00k
Timestamp 02/06/2022 10:02:27 PM
Step Count 229 Switch Count 4
Page Faults 0
Page Reclaims 549
Page Swaps 0
Voluntary Context Switches 31
Involuntary Context Switches 1
Block Input Operations 256
Block Output Operations 56056
 
 
73
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 (2,3,4);
80 run;
 
NOTE: There were 14765 observations read from the data set WORK.YRBSS.
NOTE: The data set WORK.YRBSS_2 has 8691 observations and 241 variables.
NOTE: DATA statement used (Total process time):
real time 0.05 seconds
user cpu time 0.01 seconds
system cpu time 0.04 seconds
memory 4213.18k
OS Memory 31912.00k
Timestamp 02/06/2022 10:02:27 PM
Step Count 230 Switch Count 5
Page Faults 0
Page Reclaims 579
Page Swaps 0
Voluntary Context Switches 20
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 33544
 
 
81
82 proc freq data = yrbss;
83 tables Q2 Q3 raceeth;
84 run;
 
NOTE: There were 14765 observations read from the data set WORK.YRBSS.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.05 seconds
user cpu time 0.05 seconds
system cpu time 0.00 seconds
memory 3136.62k
OS Memory 30120.00k
Timestamp 02/06/2022 10:02:27 PM
Step Count 231 Switch Count 3
Page Faults 0
Page Reclaims 333
Page Swaps 0
Voluntary Context Switches 14
Involuntary Context Switches 1
Block Input Operations 0
Block Output Operations 272
 
 
85
86 proc freq data = yrbss_2 (WHERE=(SHORTSLEEP=0));
87 tables Q2 Q3 RACEETH;
88 run;
 
NOTE: There were 6802 observations read from the data set WORK.YRBSS_2.
WHERE SHORTSLEEP=0;
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.04 seconds
user cpu time 0.04 seconds
system cpu time 0.01 seconds
memory 2309.28k
OS Memory 30120.00k
Timestamp 02/06/2022 10:02:27 PM
Step Count 232 Switch Count 27
Page Faults 0
Page Reclaims 313
Page Swaps 0
Voluntary Context Switches 75
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 280
 
 
89
90 proc freq data = yrbss_2;
91 tables Q2*SHORTSLEEP/CHISQ;
92 run;
 
NOTE: There were 8691 observations read from the data set WORK.YRBSS_2.
NOTE: PROCEDURE FREQ used (Total process time):
real time 0.04 seconds
user cpu time 0.04 seconds
system cpu time 0.01 seconds
memory 2774.65k
OS Memory 30380.00k
Timestamp 02/06/2022 10:02:27 PM
Step Count 233 Switch Count 6
Page Faults 0
Page Reclaims 380
Page Swaps 0
Voluntary Context Switches 27
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 544
 
 
93
94 data yrbss_female;
95 set yrbss;
96 if Q2 = 1;
97 run;
 
NOTE: There were 14765 observations read from the data set WORK.YRBSS.
NOTE: The data set WORK.YRBSS_FEMALE has 7526 observations and 240 variables.
NOTE: DATA statement used (Total process time):
real time 0.04 seconds
user cpu time 0.02 seconds
system cpu time 0.03 seconds
memory 4118.65k
OS Memory 32168.00k
Timestamp 02/06/2022 10:02:27 PM
Step Count 234 Switch Count 6
Page Faults 0
Page Reclaims 535
Page Swaps 0
Voluntary Context Switches 28
Involuntary Context Switches 1
Block Input Operations 0
Block Output Operations 28424
 
 
98
99 data yrbss_male;
100 set yrbss;
101 if Q2 = 2;
102 run;
 
NOTE: There were 14765 observations read from the data set WORK.YRBSS.
NOTE: The data set WORK.YRBSS_MALE has 7112 observations and 240 variables.
NOTE: DATA statement used (Total process time):
real time 0.04 seconds
user cpu time 0.02 seconds
system cpu time 0.02 seconds
memory 4116.87k
OS Memory 32168.00k
Timestamp 02/06/2022 10:02:27 PM
Step Count 235 Switch Count 6
Page Faults 0
Page Reclaims 531
Page Swaps 0
Voluntary Context Switches 27
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 26888
 
 
103
104 DATA YRBSSMALE;
105 SET yrbss_male;
106 BMI=Q7/Q6*Q6;
107 RUN;
 
NOTE: Missing values were generated as a result of performing an operation on missing values.
Each place is given by: (Number of times) at (Line):(Column).
732 at 106:7
NOTE: There were 7112 observations read from the data set WORK.YRBSS_MALE.
NOTE: The data set WORK.YRBSSMALE has 7112 observations and 241 variables.
NOTE: DATA statement used (Total process time):
real time 0.04 seconds
user cpu time 0.01 seconds
system cpu time 0.03 seconds
memory 4110.21k
OS Memory 32168.00k
Timestamp 02/06/2022 10:02:27 PM
Step Count 236 Switch Count 4
Page Faults 0
Page Reclaims 532
Page Swaps 0
Voluntary Context Switches 19
Involuntary Context Switches 2
Block Input Operations 0
Block Output Operations 27400
 
 
108
109 PROC MEANS DATA=YRBSSMALE;
110 VAR BMI;
111 RUN;
 
NOTE: There were 7112 observations read from the data set WORK.YRBSSMALE.
NOTE: PROCEDURE MEANS used (Total process time):
real time 0.02 seconds
user cpu time 0.01 seconds
system cpu time 0.01 seconds
memory 8245.03k
OS Memory 36296.00k
Timestamp 02/06/2022 10:02:27 PM
Step Count 237 Switch Count 3
Page Faults 0
Page Reclaims 1800
Page Swaps 0
Voluntary Context Switches 26
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 8
 
 
112
113
114 DATA YRBSS_WTMALE;
115 SET YRBSSMALE;
116 if BMI<18.5 THEN DELETE;
117 else if BMI>24.9 THEN DELETE;
118 RUN;
 
NOTE: There were 7112 observations read from the data set WORK.YRBSSMALE.
NOTE: The data set WORK.YRBSS_WTMALE has 0 observations and 241 variables.
NOTE: DATA statement used (Total process time):
real time 0.02 seconds
user cpu time 0.01 seconds
system cpu time 0.01 seconds
memory 3014.03k
OS Memory 30376.00k
Timestamp 02/06/2022 10:02:27 PM
Step Count 238 Switch Count 4
Page Faults 0
Page Reclaims 307
Page Swaps 0
Voluntary Context Switches 21
Involuntary Context Switches 1
Block Input Operations 0
Block Output Operations 264
 
 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 8 replies
  • 1313 views
  • 0 likes
  • 4 in conversation