这个礼拜刚开始学SAS。遇到一个问题。现在输入矩阵只会用 x={1 2 3,4 5 6,7 8 9}。可不可以复制粘贴输入矩阵呢?想了一下午,用Excel VBA编了个小程序。先把excel里的矩阵圈上,然后运行程序。就可把矩阵导成SAS的输入格式。但是总觉得绕弯子了。求正解。
VB code:
Sub Excel_matrix_to_sas()
output_cell = InputBox("请输入输出单元格位置。例如:A1")
i = Selection.Rows.Count
j = Selection.Columns.Count
st_1 = "'={"
With Selection
For m = 1 To i
For n = 1 To j
If n = 1 Then
st_1 = st_1 & .Cells(m, n).Value
Else
st_1 = st_1 & " " & .Cells(m, n).Value
End If
Next
If m <> i Or (n - 1) <> j Then
st_1 = st_1 & ","
End If
Next
st_1 = st_1 & "}"
End With
Range(output_cell).Value = st_1
End Sub