BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
MisterJenn
Fluorite | Level 6

I don't understand why I am getting 0 observations. I don't have an error code so I don't know whats going on. 

 

data fram1_temp (rename=(RANDID=subjid));
set lib14.fram1;
run;
data fram2_temp (rename=(totchol=totchol2 sysbp=sysbp2 diabp=diabp2));
set lib14.fram2;
run;
proc sort data=fram1_temp; by subjid;
proc sort data=fram2_temp; by subjid; 
data fram_merge;
merge fram1_temp fram2_temp;
by subjid;
age = (vdate-bdate)/365.25;
diff_tchol = totchol2 - totchol;
ch_tchol = sign(diff_tchol);
if sysbp > 120 and sysbp2 > 120 then both_sbp = 1;
if sysbp =< 120 or sysbp2 =< 120 then both_sbp = 0;
if sysbp = . or sysbp2 = . then both_sbp = .;
if diabp > 90 and diabp2 >90 then both_dpb = 1;
if diabp <= 90 or diabp2 <=90 then bothdbp = 0;
if diabp = . or diabp2 =. then both_dbp = .;
if bothdbp = 1 and both_sbp = 1 then both_elev = 1;
else if both_elev = 0;
If bothdbp = . and both_sbp = . then both_elev = .;
run; 

Here is the log:

 

3    data fram1_temp (rename=(RANDID=subjid));
4    set lib14.fram1;
5    run;

NOTE: There were 4434 observations read from the data set LIB14.FRAM1.
NOTE: The data set WORK.FRAM1_TEMP has 4434 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.01 seconds


6    data fram2_temp (rename=(totchol=totchol2 sysbp=sysbp2 diabp=diabp2));
7    set lib14.fram2;
8    run;

NOTE: There were 4434 observations read from the data set LIB14.FRAM2.
NOTE: The data set WORK.FRAM2_TEMP has 4434 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      cpu time            0.01 seconds


9    proc sort data=fram1_temp; by subjid;

NOTE: There were 4434 observations read from the data set WORK.FRAM1_TEMP.
NOTE: The data set WORK.FRAM1_TEMP has 4434 observations and 5 variables.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


10   proc sort data=fram2_temp; by subjid;

NOTE: There were 4434 observations read from the data set WORK.FRAM2_TEMP.
NOTE: The data set WORK.FRAM2_TEMP has 4434 observations and 5 variables.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


11   data fram_merge;
12   merge fram1_temp fram2_temp;
13   by subjid;
14   age = (vdate-bdate)/365.25;
15   diff_tchol = totchol2 - totchol;
16   ch_tchol = sign(diff_tchol);
17   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).
      504 at 14:13   675 at 15:23   675 at 16:12
NOTE: There were 4434 observations read from the data set WORK.FRAM1_TEMP.
NOTE: There were 4434 observations read from the data set WORK.FRAM2_TEMP.
NOTE: The data set WORK.FRAM_MERGE has 4434 observations and 12 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


18   libname lib14 '\\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Downloads\Final Exam';
NOTE: Libref LIB14 was successfully assigned as follows:
      Engine:        V9
      Physical Name: \\apporto.com\dfs\GWU\Users\kennedyhinnant_gwu\Downloads\Final Exam
19   run;
20   data fram1_temp (rename=(RANDID=subjid));
21   set lib14.fram1;
22   run;

NOTE: There were 4434 observations read from the data set LIB14.FRAM1.
NOTE: The data set WORK.FRAM1_TEMP has 4434 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


23   data fram2_temp (rename=(totchol=totchol2 sysbp=sysbp2 diabp=diabp2));
24   set lib14.fram2;
25   run;

NOTE: There were 4434 observations read from the data set LIB14.FRAM2.
NOTE: The data set WORK.FRAM2_TEMP has 4434 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      cpu time            0.01 seconds


26   proc sort data=fram1_temp; by subjid;

NOTE: There were 4434 observations read from the data set WORK.FRAM1_TEMP.
NOTE: The data set WORK.FRAM1_TEMP has 4434 observations and 5 variables.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


27   proc sort data=fram2_temp; by subjid;

NOTE: There were 4434 observations read from the data set WORK.FRAM2_TEMP.
NOTE: The data set WORK.FRAM2_TEMP has 4434 observations and 5 variables.
NOTE: PROCEDURE SORT used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


28   data fram_merge;
29   merge fram1_temp fram2_temp;
30   by subjid;
31   age = (vdate-bdate)/365.25;
32   diff_tchol = totchol2 - totchol;
33   ch_tchol = sign(diff_tchol);
34   if sysbp > 120 and sysbp2 > 120 then both_sbp = 1;
35   if sysbp =< 120 or sysbp2 =< 120 then both_sbp = 0;
36   if sysbp = . or sysbp2 = . then both_sbp = .;
37   if diabp > 90 and diabp2 >90 then both_dpb = 1;
38   if diabp <= 90 or diabp2 <=90 then bothdbp = 0;
39   if diabp = . or diabp2 =. then both_dbp = .;
40   if bothdbp = 1 and both_sbp = 1 then both_elev = 1;
41   else if both_elev = 0;
42   If bothdbp = . and both_sbp = . then both_elev = .;
43   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).
      504 at 31:13   675 at 32:23   675 at 33:12
NOTE: There were 4434 observations read from the data set WORK.FRAM1_TEMP.
NOTE: There were 4434 observations read from the data set WORK.FRAM2_TEMP.
NOTE: The data set WORK.FRAM_MERGE has 0 observations and 17 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

See the statement I've marked that is causing the 0 rows. I think you mean't just ELSE not ELSE IF:

data fram_merge;
merge fram1_temp fram2_temp;
by subjid;
age = (vdate-bdate)/365.25;
diff_tchol = totchol2 - totchol;
ch_tchol = sign(diff_tchol);
if sysbp > 120 and sysbp2 > 120 then both_sbp = 1;
if sysbp =< 120 or sysbp2 =< 120 then both_sbp = 0;
if sysbp = . or sysbp2 = . then both_sbp = .;
if diabp > 90 and diabp2 >90 then both_dpb = 1;
if diabp <= 90 or diabp2 <=90 then bothdbp = 0;
if diabp = . or diabp2 =. then both_dbp = .;
if bothdbp = 1 and both_sbp = 1 then both_elev = 1;
else if both_elev = 0; * This statement is filtering all rows, remov word IF ;
If bothdbp = . and both_sbp = . then both_elev = .;
run; 

View solution in original post

1 REPLY 1
SASKiwi
PROC Star

See the statement I've marked that is causing the 0 rows. I think you mean't just ELSE not ELSE IF:

data fram_merge;
merge fram1_temp fram2_temp;
by subjid;
age = (vdate-bdate)/365.25;
diff_tchol = totchol2 - totchol;
ch_tchol = sign(diff_tchol);
if sysbp > 120 and sysbp2 > 120 then both_sbp = 1;
if sysbp =< 120 or sysbp2 =< 120 then both_sbp = 0;
if sysbp = . or sysbp2 = . then both_sbp = .;
if diabp > 90 and diabp2 >90 then both_dpb = 1;
if diabp <= 90 or diabp2 <=90 then bothdbp = 0;
if diabp = . or diabp2 =. then both_dbp = .;
if bothdbp = 1 and both_sbp = 1 then both_elev = 1;
else if both_elev = 0; * This statement is filtering all rows, remov word IF ;
If bothdbp = . and both_sbp = . then both_elev = .;
run; 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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
  • 1 reply
  • 380 views
  • 0 likes
  • 2 in conversation