Performing Conditional Processing Part A
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.
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)Datalines are used to input the data
4) The 6 lines of data are there
for eg: Age =12 , Quiz = A , Midterm = 92 and Final = 95;
Task: If the Age is 12 then create a new variable value= 6 otherwise if age is 13 the value should be 7
Explanation:
For this we will use If else statement
if condition1 = true then action 1
else if condition2 = true then action 2
Task 2: The person wants to see the final coursemarks after assigning different weights to quiz final and midterm.
Problem: Quiz is a categorical variable how to deal with it?
Explanation: Lets look at the part of the above code
We are using the if else statement and comparing the Quiz Grades.
Lets Break it
1st Condition If the quiz grade is A we want the quiz grade to be 95
then if quiz grade is B we want the quiz grade to be 85
if it is C the quiz grade is 75 and 70 and 65 respectively if grade is D and E respectively
ie: We are writing the equivalent numerical values of the categorical data
hence one part of problem is solved all the datalines would pass through this loop and depending upon which condition is true it would assign the respective numerical value
But we want to calculate the coursemarks hence we would create the new variable coursemarks and assign the 20% weightage to quiz , 30% to midterm and 50% to final
coursegrades = 0.2*quizgrade + 0.3*midterm + 0.5*final
= is the assignment operator
Please find below the link of my blog where the precedence of the operators the SAS follows is given:
http://sayang8.blogspot.in/2015/09/sas-language-of-analytics-blog-1.html
Output:
For 2nd Part please click on the link below:
Learning:
In case we want to manipulate the data and compute based on the conditions specified we would go for conditional formatting. We have used a simple example of If else in this blog.
Comments
Post a Comment