Showing posts with label Combining. Show all posts

Learning SAS: Subsetting & Combining SAS Data sets

As we've learnt how to process our input data with conditions and loops, it's also equally important for us to process our SAS datasets - more prominent of which are Subsetting & Combining SAS Data sets.

Problem:

Using the SAS data set Blood, create two temporary SAS data sets by selecting all
subjects with cholesterol levels (Chol) below 100.  Do this using a single DATA step.

Input:

libname A15001 '/folders/myfolders/iSAS/Assignment';
 
data A15001.A01_Blood;
   infile '/folders/myfolders/iSAS/blood.txt' truncover;
   length Gender $ 6 BloodType $ 2 AgeGroup $ 5;
   input Subject 
         Gender 
         BloodType 
         AgeGroup
         WBC 
         RBC 
         Chol;
   label Gender = "Gender"
         BloodType = "Blood Type"
         AgeGroup = "Age Group"
         Chol = "Cholesterol";
run;

Solution:

data A15001.A01_LowCholMale A15001.A01_LowCholFemale;
 set A15001.A01_Blood;
 where Chol lt 100 and not missing(Chol); *only entries of Blood with low chol are processed;
  if Gender = 'Female' then output A15001.A01_LowCholMale;
 else if Gender = 'Male' then output A15001.A01_LowCholFemale; /* else if because it's not mutually exclusive */
run;
 
title 'List of Low Cholestrol Male'; 
proc print data=A15001.A01_LowCholMale noobs;run;
title;
 
title 'List of Low Cholestrol Female'; 
proc print data=A15001.A01_LowCholFemale noobs;run;
title;

Output:




Learning:

  1. Using WHERE to subset SAS Datasets
  2. Creating multiple SAS Datasets in a single DATA step
  3. Controlling the implicit OUTPUT to write in specific dataset based on specific conditions



Saturday, September 19, 2015
Posted by Netbloggy

Popular Post

Blogger templates

Total Pageviews

Powered by Blogger.

- Copyright © nulldata -Metrominimalist- Powered by Blogger - Designed by Johanes Djogan -