如何使用proc sql?h计算SAS数据集中的观测值

时间:2016-06-01 16:51:15

标签: sas

我需要更新以下代码来做两件事: 1)proc sql有一个名为Type的变量,它将数据集分为四组。我需要分别计算每个组中的观察数量。如何更新我的程序来做到这一点? 2)我想创建一个具有观察数量的新数据集。下面的程序给我在日志页面中的数字,但我想创建一个新的数据集。我该如何编程?

如果除proc sql noprint; select count(*) into :nobs from sourceh.group2; quit; %put Obs in data set: &nobs; 之外还有更有效的方法来执行这些非常有用的方法,那么它就是一个大型数据集。

谢谢!

Nothing

2 个答案:

答案 0 :(得分:2)

对于第一个问题,您只需创建一个具有类型的表,该类型的观察计数,并按类型对其进行分组。对于你的第二个问题,你做同样的事情,但没有小组(因为你只需要观察总数):

// refer to the code in: http://sol.gfxile.net/instancing.html
// refer to the code in: http://www.gamedev.net/page/resources/_/technical/opengl/opengl-instancing-demystified-r3226
// Case: instaced vertex positions. So each instance should have 4 vec2
{
    // in mat4x2;  later try in vec2[4] xyInBaseImage_vec2list if mat4x2 does not work.
    GLuint instanceVBO = instancevbo_4pts;
    int pos = 1;
    int componentsSize = 2;  // vec2 has 2 components
    // if it is mat, then componentsNum is the column number of the matrix; for example, for mat4x2 it is 4
    int componentsNum = 4; // mat4x2
    GLenum type = GL_FLOAT;
    GLboolean normalized = GL_FALSE;
    GLsizei stride = componentsSize * sizeof(GL_FLOAT) * componentsNum;
    char* pointerFirstComponentOffset = 0;
    int offsetInteger = 0;
    int byteSizeOfOneVertexAttribute = componentsSize * sizeof(GL_FLOAT);
    GLuint divisor = 1;  // 0 not instance
    glBindBuffer(GL_ARRAY_BUFFER, instanceVBO);
    for (int i = 0; i < componentsNum; i++) {
        glEnableVertexAttribArray(pos + i);
        // the offset can also be: (void*) (offsetInteger + i * byteSizeOfOneVertexAttribute)
        glVertexAttribPointer(pos + i, componentsSize, type,
                                                     normalized, stride, pointerFirstComponentOffset + i * byteSizeOfOneVertexAttribute  );
        glVertexAttribDivisor(pos + i, divisor);
    }
    glBindBuffer(GL_ARRAY_BUFFER, 0);
}

答案 1 :(得分:1)

您可能想要使用PROC SUMMARY。它可以让你在一次运行中按TYPE,CAP或两者都计算。

 proc summary data=have ;
   class type cap ;
   output out=counts ;
 run;

变量_TYPE_将告诉您哪些类变量对表有贡献。使用两个类变量,您将有四个_TYPE_值。 00将具有总计数,1将具有CAP级别的计数,2(&#39; 10&#39; b)将具有TYPE和3的级别计数(&#39; 11&#39; b)将具有TYPE和CAP等级的值。