Posts

Showing posts from September, 2015

Subsetting and Combing the Datasets

Image
In this blog we would look at some programmes on how to do subsetting of the data  and how to combine the data from several to single datasets. Subsetting a SAS datastep involves selecting observations from one data set by defining the selection criteria either where , if/else , select  among many others. Lets look at the questions to get better understanding  Q Code: Code: 1) We are creating a new dataset A35_a in library A15035 2) We are reading the observations from blood dataset in library A15035. 3) We are partitioning the data based on the condition using the where keyword when gender equals female and bloodtype is AB. 4) We are creating the new variable combined computing the value based on the condition specified. 5) Then we are using the proc print to print the observations from the dataset A35_a 6) In the next part we are creating a new dataset A35_b in library A15035 7) We are reading the observations from blood datas...

Performing Conditional Processing Part B: Learning SAS by Example Questions Solved

Image
Hi Folks!! Welcome to the second part of the blog where we would aim at understanding how do conditional formatting helps in "making decisions" based on data values. We have earlier done 1 Question in Part 1 here we would be solving the other 5 Question given in the book Learning SAS by example. Q1) Lets see the code and try to understand the same: Code:           The 1st snippet creates the hospital dataset in the library A15035. Our focus is to understand the use of in and or operator. In and or operator helps in getting the same output. Let us understand after breaking the two codes Proc print is used to print the observations in the A35_hosp dataset from A15035 library where has been  used to put some constraints ordering the command to output the observations based on conditions specified after the where clause Or statement is simply checking if the subject values are 5,100,150 and 200 then only print the obser...

Performing Conditional Processing Part A

Image
Hi Folks Welcome back!!   SAS is a software for various applications like business intelligence, predictive analytics among many others. Lot of companies have deployed this software due to its powerful statistical benefits. As an analyst one must be aware of how we work on this software. For this purpose we are writing this blog. The mode of explanation would be covered via question and answer mode. We are referring to the book Learning SAS by example Programmer's guide by Ron Cody This is a very easy and lucid book . One can refer to in terms of basics and is like a bible for beginners.  Indian Edition costs around Rs-5000 . The topic for this blog is Conditional Formatting : If Else Statement. Q1: Code: Question Requirement: 1) In the above code we are creating a dataset A35_school in library A15035. 2) The attributes are age (numeric) , quiz (character with length 1 denoted as $1),midterm (numeric) and final(numeric) 3)...

SAS Blog 3: Formats and Labels

Image
Welcome to the 3rd set of blog  The topic under discussion is formats and labels. The SAS gives us an advantage to create user defined formats and manipulate the display as per our requirements. Here also we are taking an example of a question and we will look into the scenario where we would be creating our own user defined formats . Q1) Create the below mentioned dataset voter: Code: /*Part1*/ proc format; value age 0-30 = 'Between 0 and 31' 31-50 = 'between 31 and 50' 51-70 = 'between 51 and 70' 71-High = 'greater than 71'; value $party N = 'National Democratic alliance' U = 'United Progressive Alliance' ; value $hello 1 = 'strongly disagree' 2 = 'disagree' 3 = 'no opinion' 4 = 'agree' 5 = 'strongly agree' ; /*part2*/ data voter; input Age Party : $1.(Ques1-Ques4)($1.+1); format Age age. party $party. Ques1-Ques4 $hello.; label Ques1 = 'prime minister is doing a good job' Q...

Blog 2:Importing and Exporting excel File in SAS

Image
Welcome back to blog 2. Today's area of discussion is to import and export the excel file. Use proc import to convert the  spreadsheet drugtest. Use proc print to list down the observations in this dataset Code: The main aim of this programme for import and export the excel */ /*Question1*/ 1)proc import 2)out= work.drugtest 3)datafile = 'C:\Users\Elcot\Desktop\SAS\neha sas cody book\Practice set 4\drugtest.xls' 4)dbms=xls 5)replace; 6)sheet = "sheet1"; 7)getnames = yes; 8)run; 9)proc print data = drugtest; 10)run; Solution/Explanation: 1) proc import is the procedure to import the file 2) out states the destination where the file would be saved here it is in work library and the data set is named drugtest. 3)datafile states the path where the file is saved which is to be imported 4) dbms refers to the format of the file 5) replace overwrites an already existing data set 6)sheet refers to the sheet name 7)getnames refers to the columns names ...

SAS Blog 1 Part 3: Working with simple datasets

Image
Lets cover one more question Write a program, using datalines, to load a permanent SAS data set called “patient” from data below: ID Gender DoB Height Weight 001 M 21/10/1946 171 70.1 002 F 26/5/1950 163 55.5 003 M 11/5/1981 180 81.4 004 M 4/7/1983 174 56.3 005 F 25/12/2009 80 25.1                        Use appropriate format for the variables. Run PROC CONTENTS on this data set Use SAS Studio to investigate the properties of this data set Run PROC PRINT on the data set you created Code: libname test "C:\Users\Elcot\Desktop\Term1\SAS Folders"; data test.patient; input i...

SAS Blog 1 Part 2 : Working with simple data sets

Image
Lets look into further questions. I am picking few questions to make you understand the variety while working on simple datasets Code: filename geo "C:\Users\Elcot\Desktop\Term1\SAS Folders\Day 2\Set_1\geocaching.txt"; data geocaching; infile geo ;  input Name $1-20 longdeg 21-22 longmin  23-28 latdeg 29-30 latmin 31-36; run; proc print data = geocaching; run; proc contents data= geocaching; run; Important: here we specifying the range of column input like for name it is from 1-20 here we are directing the data statement to read from 1-20, then longdeg from 21-22,longmin from 23-28 and so on Other way of writing the code filename geo "C:\Users\Elcot\Desktop\Term1\SAS Folders\Day 2\Set_1\geocaching.txt"; data geocaching; infile geo ;  input @1 Name  $19. @21 longdeg  2. @23 longmin   5. @29 latdeg  2. @31 latmin  6. ; run; In this we are using the column pointer to specify the start of the column like for name it ...

SAS The language of Analytics Blog 1: Working with simple data sets

Image
Welcome back to the world of analytics. Today's scope of coverage is how to write a simple SAS Programme.   About SAS:  This is a very powerful tool that has been used across companies to take advantage of its statistical   capability.  The methodology adopted in this blog is through questions and understanding the output and code lines: You have a text file called scores.txt containing information on gender (M or F) and four test scores (English, history, math, and science). Each data value is separated from the others by one or more blanks.   a.     Write a DATA step to read in these values. Choose your own variable names. Be sure that the value for Gender is stored in 1 byte and that the four test scores are numeric. b.     Include an assignment statement computing the average of the four test scores. c.     Write the appropriate PROC PRINT statements to list the...