sqlsasproc-sql

SAS output has empty columns for proc SQL


Here is all of the code

Code:

data BTC1;

input date mmddyy10. open close;

cards;

12/28/2021 50679.85 47588.85

12/29/2021 47623.87 46444.71

12/30/2021 46490.60 47178.12

12/31/2021 47169.37 46306.44

1/1/2022 46311.74 47686.81

1/2/2022 47680.92 47345.21

1/3/2022 47343.54 46458.11

1/4/2022 46458.85 45897.57

;

data BTC2;

input date mmddyy10. open close;

cards;

12/31/2021 47169.37 46306.44

1/1/2022 46311.74 47686.81

1/2/2022 47680.92 47345.21

1/3/2022 47343.54 46458.11

1/4/2022 46458.85 45897.57

1/5/2022 45899.35 43569.00

1/6/2022 43565.51 43160.92

1/7/2022 43153.57 41557.90

;
proc sql;
    
select BTC1.date , open, close
    
from BTC1 except
     
Select *
    
from BTC2;
    
quit;

Here is the associated ouput i get (see picture) Date Column is empty AND the open column is Empty

I have tried numerous forums online and can only seem to get an answer based on removing columns which doesnt help me in this case. I know the answer is simple so i expect to be slammed for this but its basic SAS and it's driving me bananas.


Solution

  • Your INPUT statements are wrong. You are telling SAS to read the first 10 bytes of the line into the DATE variable. But for some of those rows the first 10 bytes include the start of the next variable.

    Use the colon modifier on the INPUT statement to let SAS know you want to read the data in LIST MODE even though you have included an informat specification in the INPUT statement.

    input date :mmddyy10. open close;
    

    If your issue is with the EXCEPT operation in the SQL code then perhaps the rows that look identical to you are not actually identical. For example those fractional numbers might have some small differences in the way they are stored as floating point binary numbers that are not larger enough to change how they are printed as decimal digits.

    You could try using the ROUND() function on every numeric variable in both datasets to make sure they will actually be the same when then look the same.