SAS The language of Analytics Blog 1: Working with simple data sets
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.
b. Include
an assignment statement computing the average of the four test scores.
c. Write
the appropriate PROC PRINT statements to list the contents of this data set.
Code
1./*To calculate the average of the scores*/
2.title " Result of question1"
3.data scores;
4.infile "C:\Users\Elcot\Desktop\Term1\SAS Folders\Day 2\Set_1\scores.txt";
5.input gender $1 score1 score2 score3 score4 ;
6.avescore = mean(of score1-score4);
7.run;
8.proc print data = scores;
9.run;
10.proc contents data = scores;
11.run;
There are broadly two statements data and proc steps. Data statements are used to manipulate data, input data etc whereas proc which corresponds to procedure which is used to summarizing reports and displaying output.
Lets drill down each line
1) /* ….. */: It is the method to write the comments in the SAS
2) Title is used to give the heading and it is one of the global statements which are valid for each sas session
3) This is using the data statement to create a file scores in the temporary folder work.
4) Infile statement is used to import the file here we are importing the notepad file
5) Input is used to declare the variables here gender is character variable other score 1 to score 4 are numeric . By default the size is 8 bytes but here we are declaring the size of gender as 1 byte
6) In this statement we are declaring a new variable avescore and = is used for assignment and mean function to calculate the mean
7) Run is important to end the data or proc statement
8) Proc print is the procedure to display the output of output in scores file.
9) Run is important to end the data or proc statement
10) Proc contents to display the contents of the text file scores
1) /* ….. */: It is the method to write the comments in the SAS
2) Title is used to give the heading and it is one of the global statements which are valid for each sas session
3) This is using the data statement to create a file scores in the temporary folder work.
4) Infile statement is used to import the file here we are importing the notepad file
5) Input is used to declare the variables here gender is character variable other score 1 to score 4 are numeric . By default the size is 8 bytes but here we are declaring the size of gender as 1 byte
6) In this statement we are declaring a new variable avescore and = is used for assignment and mean function to calculate the mean
7) Run is important to end the data or proc statement
8) Proc print is the procedure to display the output of output in scores file.
9) Run is important to end the data or proc statement
10) Proc contents to display the contents of the text file scores
You want to create a test data set that uses a DATALINES statement to read in values for X and Y. In the DATA step, you want to create a new variable, Z, equal to 100 + 50X + 2X2 – 25Y + Y2. Use the following (X,Y) data pairs: (1,2), (3,6), (5,9), and (9,11).
Code:
data random;
input X Y;
z = (100 + 50*X + (2*X)**2 - 25*Y + Y**2);
datalines;
1 2
3 6
5 9
9 11
;
run;
proc print data=random;
run;
Explanation: Datalines are used to input the data and the most important part here is the z variable the calculation basically follows the below mentioned route: Paranthesis are also given preferences among any other operation
Output:
a) Never forget to end a statement with run ; otherwise the programme would not be executed
Reference: Leaning SAS by example
Follow next blog for coverage of other topics
Overall, good work.
ReplyDeleteCorrections:
1. Data Step and Proc steps
2. grill --> should be drill
3. Statements end with ";" and Steps end with "Run;" statements.
Improvement suggestions:
1. the code will look better, if you can copy code from screen thru' screen grab mechanism.
2. Try to write it in such a manner, so that you can tell others (like job interviewer) to look at your blog.
By the way, have you forgotten to attach the zip file containing your programs and data?
Great blog.you put Good stuff.All the topics were explained briefly.so quickly understand for me.I am waiting for your next fantastic blog.Thanks for sharing.Any coures related details learn...
ReplyDeleteSAS Online Training |
Tableau Online Training|
R Programming Online Training|
Its really good to know about that some facts and other informative points given here are quite considerable.thanks a lot.
ReplyDeleteC and C++ Training Institute in chennai | C and C++ Training Institute in anna nagar | C and C++ Training Institute in omr | C and C++ Training Institute in porur | C and C++ Training Institute in tambaram | C and C++ Training Institute in velachery
I appreciate that you produced this wonderful article to help us get more knowledge about this topic.keep it up!!
ReplyDeleteandroid training in chennai
android online training in chennai
android training in bangalore
android training in hyderabad
android Training in coimbatore
android training
android online training