basic programming for data analysis
DESCRIPTION
BASIC PROGRAMMING FOR DATA ANALYSIS. Dr. D. Dutta Roy Psychology Research Unit Indian Statistical Institute 203, B.T. Road Kolkata- 700108. CONTENTS. Introduction : - PowerPoint PPT PresentationTRANSCRIPT
BASIC PROGRAMMING FOR DATA ANALYSIS
Dr. D. Dutta RoyPsychology Research UnitIndian Statistical Institute
203, B.T. RoadKolkata- 700108
2Dr. D. Dutta Roy, Indian Statistical Institute, [email protected]
08:47 AM 08:47 AM
CONTENTS
• Introduction:– Definition, Types of Programming languages,
Characteristics of good algorithm, Flowchart, Programming structure , Data analysis
• Data entry: File handling, reading and printing data, Array, Operators, Commands, Data entry, Statements, Adv.functions
• Data computation :Max score, – result reporting
08:47 AM 08:47 AM Dr. D. Dutta Roy, Indian Statistical Institute, [email protected]
3
What is BASIC ?
• BASIC is an useful programming languages for data entry, data analysis and reporting the result. In programming, there are three languages: Machine level/low level (High state and low state or 1 and 0) and higher level languages. BASIC is a higher level language. BASIC means “ Beginner’s All Purpose Symbolic Instructions Code. Computer does not understand the higher level language so higher level language is converted to machine language. Between these two languages, assembly level language exists. It involves a set mnemonic codes. BASIC is simple and easy-to-learn language, particularly suitable for the non-specialist users.
08:47 AM 08:47 AM Dr. D. Dutta Roy, Indian Statistical Institute, [email protected]
4
What is Programming ?• Programming is a set of commands or statements given to
the computer in some computer language. These commands will be executed by the computer in a particular sequence. The list of commands given to the computer for solving a problem is called computer program.Any program written in high level language has to be translated into machine language before it is executed by the computer. This can be achieved with the help of translator programs - compilers (translating entire program and executing the program)and interpreters (translating each step and executing it). BASIC programs are normally interpreted not compiled.
08:47 AM 08:47 AM Dr. D. Dutta Roy, Indian Statistical Institute, [email protected]
5
Algorithms
• Algorithm is a step-by-step procedure for solving a given problem. The characteristics of good algorithm are:– They are simple but offer powerful and general solutions– They are well documented to be used and easily
understood by others– They can be modified easily– They give correct solutions– They save computer time and memory space.– They can be used as sub-procedures for other problems.
08:47 AM 08:47 AM Dr. D. Dutta Roy, Indian Statistical Institute, [email protected]
6
Flow chart
• Flow charting is a diagrammatic representation of the problem solving process, in which decision steps are laid out in logical order.
08:47 AM 08:47 AM Dr. D. Dutta Roy, Indian Statistical Institute, [email protected]
7
OperatorsVariablesNumeric Numeric constat, followed by alphabet
A, A12, A%String String of characters or alphanumeric constants
A$, ADD$OperatorsArithmetic +, -, *, /, ^Relational = , <, >, <>, <=, >='
Logical AND, OR, NOT
8Dr. D. Dutta Roy, Indian Statistical Institute, [email protected]
08:47 AM 08:47 AM
Programming Structure
• Array creation • Opening the input,output,append file• Input/read data• Analysis of data as per programming flow• Displaying the output through file or through
display unit as per user requirement• End
08:47 AM 08:47 AM Dr. D. Dutta Roy, Indian Statistical Institute, [email protected]
9
ARRAYArray is used to store a large amount of data temporarily to different variables. There are two types of array: One dimensional array and two dimensional array.Syntax of one dimensional array
Dim <arrayname> (max.data number)Dim Data (10)
Syntax of Two dimensional arrayDim <arrayname> (max.row, max.col.)Dim Data (10,5)
08:47 AM 08:47 AM Dr. D. Dutta Roy, Indian Statistical Institute, [email protected]
10
Opening and Closing FilesInput and Output statement
One can open atleast 15 files at a time .
Open open n$ for input as #1open n$ for output as #2open n$ for append as #3
Close CloseClose # 3
Read Read DataInput Input "name",name$
Input "age ",ageInput #1, name$, age
08:47 AM 08:47 AM Dr. D. Dutta Roy, Indian Statistical Institute, [email protected]
11
BASIC STATEMENT COMMANDS
Transfer statement GOTO 10GOSUB - RETURN
Conditional statement IF-THEN-ELSEON A GOSUB 10,20ON A GOTO 10,20SELECT CASE
Loop Statement FOR - NEXT
08:47 AM 08:47 AM Dr. D. Dutta Roy, Indian Statistical Institute, [email protected]
12
TRANSFER STATEMENT
• GOTO <LINE NO.>• GOSUB <LINE NO.>...RETURN
08:47 AM 08:47 AM Dr. D. Dutta Roy, Indian Statistical Institute, [email protected]
13
Conditional statement(IF-THEN)
• IF-THEN-ELSE– IF condition 1 THEN statement block 1ELSE IF condition 2 THEN statement block 2ELSE statement block nENDIF
08:47 AM 08:47 AM Dr. D. Dutta Roy, Indian Statistical Institute, [email protected]
14
• ON EXPRESSION% GOTO LINE LIST.• ON EXPRESSION% GOSUB LINE LIST.
Conditional statement(ON GOTO)
08:47 AM 08:47 AM Dr. D. Dutta Roy, Indian Statistical Institute, [email protected]
15
Co
Select case <variable name>case is >= 1statement block1case 2 to 4statement block2case 1statement block 3end select
Conditional statement(SELECT)
08:47 AM 08:47 AM Dr. D. Dutta Roy, Indian Statistical Institute, [email protected]
16
Flow of BASIC program
• There are three types of flow in writing the program:– Sequential flow(working instructions
sequentially)– Repetitive flow(doing same job repeatedly)– Conditional repetitive flow(Flow depends upon
satisfaction of condition)
08:47 AM 08:47 AM Dr. D. Dutta Roy, Indian Statistical Institute, [email protected]
17
Data analysis
• There are three phases of data analysis:– Data entry: data coding and feeding to
computer, data tabulation and verification– Data analysis: selection of useful measurement
techniques and writing program– Display of results: Displaying the data
following user’s specification
08:47 AM 08:47 AM Dr. D. Dutta Roy, Indian Statistical Institute, [email protected]
18
DATA ENTRY AND CODING
• CLS• REM This program is for entering the data and coding the variables• OPEN "c:\windows\desktop\test.dat" FOR APPEND AS #1• LOC1 = 1• LOC2 = 2• 10 INPUT "NAME OF STUDENTS ", NAME$• IF NAME$ = "0" THEN GOTO 100• INPUT "AGE ", AGE• INPUT "LOCALITY (TYPE U FOR URBAN AND R FOR RURAL)
", LOC$• INPUT "MATHEMATICS EXAM. SCORE ", MATH• IF LOC$ = "U" THEN WRITE #1, NAME$, AGE, LOC1, MATH• IF LOC$ = "R" THEN WRITE #1, NAME$, AGE, LOC2, MATH• GOTO 10• 100 END
19Dr. D. Dutta Roy, Indian Statistical Institute, [email protected]
08:47 AM 08:47 AM
Advance FunctionsCONVERT ANY FUNCTION TO
CINT I=CINT (X)
FIX Y=FIX(X) TRUNCATING REAL TO INTEGER
CDBL CDBL(A) CONVERTING SINGLE PRECISION
WIDTH WIDTH 40 SETTING NO. OF CHARACTERS IN A
CHDIR CHDIR "A:\TEST" CONTROL GOTO NEW DIRECTORY
MKDIR MKDIR "B:\HARI" MAKING NEW DIRECTORY
KILL KILL "A:\TEST.OUT" KILLING DEFINED FILE
RMDIR RMDIR "A:\HARI" REMOVING HARI DIRECTORY
FILES FILES "A:*.DAT" SHOWING ALL FILES WITH GIVEN
NAME NAME "TEST.BAS" AS "TEST2.BAS" CHANGING EXISTING
SHELL/EXIT SHELL GOING TO DOS
CLEAR CLEAR SETTING ALL NUMERIC
08:47 AM 08:47 AM Dr. D. Dutta Roy, Indian Statistical Institute, [email protected]
20
Matrix Manipulation• A matrix is a rectangular
array of numbers. In matrix algebra, the array is considered to be a single unit rather than collection of individual entries, and is operated upon as a unit. For calculation of two matrices, there should be the same number of rows and columns.
• A = 105 63 5 218 80 2 220 76 1 84 102 4
• B = 240 121 1 302 28 0
08:47 AM 08:47 AM Dr. D. Dutta Roy, Indian Statistical Institute, [email protected]
21
Addition of two matrices
REM program to add matrices of two sets of dataDIM a(3, 3), b(3, 3), c(3, 3)n = 3: m = 3FOR i = 1 TO nFOR j = 1 TO mREAD a(i, j)DATA 105,63,5,218,80,2,220,76,1PRINT a(i, j)NEXT jNEXT iPRINT
"========================================="
FOR k = 1 TO n FOR l = 1 TO m READ b(k, l)DATA 84,102,4,240,121,1,302,28,0PRINT b(k, l)NEXT lNEXT k
FOR mr = 1 TO n FOR mc = 1 TO m c(mr, mc) = a(mr, mc) + b(mr, mc) NEXT mc NEXT mrPRINT”+++++++++++++++++++++++++”
FOR g = 1 TO n FOR h = 1 TO m PRINT c(g, h) NEXT h NEXT g