Hi, I have been using Python to process data all the time. Now I'm trying to study SAS. I'm struggling with the code below, and couldn't figure out how to use SAS to do so. Could anyone help me with this? # -*- coding: utf-8 -*- """ Created on Wed Nov 28 19:18:27 2018 @author: Luke """ import pandas as pd import numpy as np import statsmodels.api as sm dataset = pd.read_csv("D:\Python\Data3.csv", index_col=0,encoding='gbk') result = {'Name':'LinearRgression Result'} dic = {} for j in range(30,7*360,30): list1 = [] list2 = [] for i in range(2880-j+1): data = dataset.iloc[i:i+j-1,0:8] X = data[['t7 ']] y = data['t8'] X = sm.add_constant(X) est = sm.OLS(y,X).fit() predReturn = est.params.t7 * dataset.iloc[i+j,6] + est.params.const #+ est.params.t7 * dataset.iloc[i+j,6] diff1 = dataset.iloc[i+j,7]-predReturn list1.append(diff1) diff2 = dataset.iloc[i+j,7]-data.iloc[0:,7].mean() list2.append(diff2) sum1 = 0 sum2 = 0 for k in list1: sum1 = sum1 + k ** 2 for k in list2: sum2 = sum2 + k ** 2 dic['%d'%j]=1-sum1/sum2 print(j/360/7*100,'%') for i in dic.keys(): print(dic[i])
... View more