SAS proq SQL:有条件地汇总和折叠行

时间:2018-10-24 01:28:19

标签: sql sas sum proc proc-sql

在SAS中,如何有条件地折叠行,而用显式命名的单行代替值的总和?

具体来说,我正在寻找创建一个频率表,该频率表显示值 Subclass 的频率,但是条件是该频率> 9。在任何其他情况下(频率<10),我希望频率计入限制为值 Class 的频率之和。数据集中没有任何缺失或0值。

Freq   Class  Subclass 
---------------------
20     1      1a        
20     1      1b       
 2     1      1c  
 2     1      1d
 2     1      1e
 1     1      1f
22     2      2a       
 6     2      2b        
 2     2      2c
 1     2      2d
31     3      3a        
17     3      3b        
 7     3      3c
 3     3      3d  
 3     3      3e        

我当前的方法使用以下方法生成了第一个表:

proc sql;
   create table as
   select* count (distinct subjectID) as count
   from DATASET1 
   group by Subclass
   ; 
run; quit;

所需的结果如下所示:

Freq   Class  Subclass 
---------------------
20     1      1a        
20     1      1b       
 7     1      OTHER (1c, 1d, 1e, 1f) 
22     2      2a       
 9     2      OTHER (2b, 2c, 2d)        
31     3      3a        
17     3      3b        
13     3      OTHER (3c, 3d, 3e)     

最好,我想根据行中表示的度量的标识符,另外明确地命名表示总和度量的 Subclass 值。在此示例中,这将是子类的名称总和。

我尝试使用Proc means过程,该过程将产生频率为<10而不是总和的所有Subclasses的新数据集。

2 个答案:

答案 0 :(得分:1)

数据步骤是利用button.disableProperty().bind(Bindings.createBooleanBinding( () -> (combo.getValue() == null) || textfield.getText().trim().isEmpty(), textfield.textProperty(), combo.valueProperty() )); first.语句获取首选输出的方法。这使您可以选择输出> 9的值或对同一类中的其他值求和。

last.函数将连接子类值,因此您可以看到哪个值构成了频率。

call catx

答案 1 :(得分:0)

未经测试的代码,这将使您很容易理解如何通过使用联合来解决该问题。

    # Enter a new user name and password to use as the local administrator account 
    # for remotely accessing the VM.
    $cred = Get-Credential

    # Name of the storage account where the VHD is located. This example sets the 
    # storage account name as "myStorageAccount"
    $storageAccName = "myStorageAccount"

    # Name of the virtual machine. This example sets the VM name as "myVM".
    $vmName = "myVM"

    # Size of the virtual machine. This example creates "Standard_D2_v2" sized VM. 
    # See the VM sizes documentation for more information: 
    # https://azure.microsoft.com/documentation/articles/virtual-machines-windows-sizes/
    $vmSize = "Standard_D2_v2"

    # Computer name for the VM. This examples sets the computer name as "myComputer".
    $computerName = "myComputer"

    # Name of the disk that holds the OS. This example sets the 
    # OS disk name as "myOsDisk"
    $osDiskName = "myOsDisk"

    # Assign a SKU name. This example sets the SKU name as "Standard_LRS"
    # Valid values for -SkuName are: Standard_LRS - locally redundant storage, Standard_ZRS - zone redundant
    # storage, Standard_GRS - geo redundant storage, Standard_RAGRS - read access geo redundant storage,
    # Premium_LRS - premium locally redundant storage. 
    $skuName = "Standard_LRS"

    # Get the storage account where the uploaded image is stored
    $storageAcc = Get-AzureRmStorageAccount -ResourceGroupName $rgName -AccountName $storageAccName

    # Set the VM name and size
    $vmConfig = New-AzureRmVMConfig -VMName $vmName -VMSize $vmSize

    #Set the Windows operating system configuration and add the NIC
    $vm = Set-AzureRmVMOperatingSystem -VM $vmConfig -Windows -ComputerName $computerName `
        -Credential $cred -ProvisionVMAgent -EnableAutoUpdate
    $vm = Add-AzureRmVMNetworkInterface -VM $vm -Id $nic.Id

    # Create the OS disk URI
    $osDiskUri = '{0}vhds/{1}-{2}.vhd' `
        -f $storageAcc.PrimaryEndpoints.Blob.ToString(), $vmName.ToLower(), $osDiskName

    # Configure the OS disk to be created from the existing VHD image (-CreateOption fromImage).
    $vm = Set-AzureRmVMOSDisk -VM $vm -Name $osDiskName -VhdUri $osDiskUri `
        -CreateOption fromImage -SourceImageUri $imageURI -Windows

    # Create the new VM
    New-AzureRmVM -ResourceGroupName $rgName -Location $location -VM $vm