Guide To Master SAS Programming
Guide To Master SAS Programming
Guide To Master SAS Programming
TOPIC PAGE NO
DATA STATEMENT 1
INFILE STATEMENT 1
INPUT STATEMENT 5
CONDITIONAL STATEMENTS 15
ITERATIVE DO LOOPS 19
DM STATEMENT 21
COMBINING DATASETS 22
FUNCTIONS 35
OPTIONS 51
ARRAYS 58
PROC CONTENTS 65
PROC COMPARE 67
PROC TRANSPOSE 70
PROC MEANS 72
PROC FREQUENCY 73
PROC PRINT 75
PROC REPORT 79
MACROS 90
SQL 101
DATA STATEMENT
INFILE STATEMENTS
DATA E_1;
INFILE DATALINES;
INPUT STARTING $ 5-19 DESTINATION $ 21-36 DISTANCE $ 37-48;
DATALINES;
NEWYORK LOS ANGELS 2,446.32 mi
DALLAS San-Diego 1,181.13 mi
San-Francisco New-York 2,463.84 mi
Las-Vegas Atlanta 4,403.12 mi
;
RUN;
DATA E_3;
INFILE DATALINES DSD;
INPUT STARTING :$18. DESTINATION $DISTANCE $;
DATALINES;
NY,LA,2,446.32
DALLAS,SD,1,181.13
SF,NY,2,463.84
LV,Atlanta,4,403.12
;
RUN;
DATA E_3;
INFILE DATALINES DSD;
INPUT STARTING :$18. DESTINATION $DISTANCE $;
DATALINES;
NY,,2,446.32
DALLAS,SD,,181.13
SF,NY,2,463.84
LV,Atlanta,4,403.12
;
RUN;
DLM: WHEN THE RAW DATA HAS THE SPECIAL CHARACTER OTHER THAN
COMMA WE USE DLM. THE SPECIAL CHARACTERS MUST BE ENCLOSED IN THE
QUOTES.
DATA E_4;
INFILE DATALINES DLM='^';
INPUT STARTING :$18. DESTINATION $DISTANCE $;
DATALINES;
NY^LA^2446.32
DALLAS^SD^1181.13
SF^NY^2463.84
LV^Atlanta^4,403.12
;
RUN;
DATA E_5;
INFILE "C:\Users\RICKY\Desktop\BQ\_DM.TXT" DLM='%';
INFILE NAME $ AGE $ SEX $ RACE $ HEIGHT WEIGHT;
RUN;
MISSOVER: WHEN THE VALUES ARE MISSING IN THE LAST VARIABE WE USE
MISSOVER.IN THE BELOW EXAMPLE SECOND OBSERVATION RACE IS
MISSING.
DATA E_5;
INFILE DATALINES MISSOVER;
INPUT SUBJID AGE GENDER $ RACE $;
DATALINES;
101 23 MALE WHITE
102 56 MALE
103 27 FEMALE ASIAN
;
RUN;
DATA E_6;
INFILE DATALINES MISSOVER;
INPUT SUBJID AGE ETHNIC $ RACE $ HEIGHT WEIGHT;
DATALINES;
101 23 Asian White 5.6 67
102 45 Asian
103 20 INDIAN Black 4.5 56
104 40 Asian Black
105 23 CANADIAN
106 34 Asian Black 7.3 87
;
RUN;
DATA E_7;
INFILE DATALINES FIRSTOBS=2 MISSOVER;
INPUT SUBJID AGE ETHNIC $ RACE $ HEIGHT WEIGHT;
DATALINES;
101 23 Asian White 5.6 67
102 45 Asian
103 20 INDIAN Black 4.5 56
104 40 Asian Black
105 23 CANADIAN
106 34 Asian Black 7.3 87
;
RUN;
data DETAILS;
infile cards;
input empid 1-8 name $ 9-26 des $ 27-34;
cards;
1001 SAM AMMAR Tester
1002 JOSH SAM PANDA Analyst
;
RUN;
DATA EMP3;
INFILE DATALINES;
INPUT ID 3. NAME &$8. SALARY 6.;
DATALINES;
101 BEZ 15000
102 GEZAJ 16450
103 RUBEN 14587
;
RUN;
DATA EMP3;
INFILE DATALINES;
INPUT ID 3. NAME &$8. SALARY 6.;
DATALINES;
101 BEZ 15000
102 GEZAJ 16450
103 RUBEN 14587
;
RUN;
DATA EMP6;
INFILE DATALINES;
INPUT #1 ID 3.
#2 NAME &$8.
#3 SALARY 6.;
DATALINES;
101
BEZ
15000
102
GEZAJ
16450
103
RUBEN
14587
;
RUN;
POINTER : SYMBOL: THIS POINTER READS THE VALUES BETWEEN THE
NON-BLANK COLUMN.IRRESPECTIVE OF THE BLANK SPACE LENGTH. IT IS
ALSO USED WHEN DELIMITERS ARE USED.
DATA EMP4;
INFILE DATALINES;
INPUT ID :3. NAME :$8. SALARY 6.;
DATALINES;
101 BEZ 15000
102 GEZAJ 16450
103 RUBEN 14587
;
RUN;
DATA EMP5;
INFILE DATALINES DSD;
INPUT ID :3. NAME :$8. SALARY 6.;
DATALINES;
101,BEZ,15000
102,GEZAJ,16450
103,RUBEN,14587
;
RUN;
DATA EMP6;
INFILE DATALINES;
INPUT SEX $18-19@;
IF SEX='M';
INPUT ID 1-3 NAME &$ 5-11 SALARY 12-17 SEX $ 18-19;
DATALINES;
101 BEZ 15000 M
102 GEZAJ 16450 F
103 RUBEN 14587 M
;
RUN;
INFORMATS
DATA E_10;
INFILE DATALINES;
INPUT EMP_ID DES $:10. JDATE RDATE;
INFORMAT JDATE RDATE DDMMYY10.;
DATALINES;
101 BAKER 10/11/2014 09/11/2019
102 BANKER 01/05/2013 09/12/2020
103 BROKER 14/05/2011 04/05/2018
;
RUN;
DATA E_13;
INFILE DATALINES;
INPUT EMP_ID DES $:10. JDATE RDATE;
INFORMAT JDATE RDATE DATE9.;
DATALINES;
101 BAKER 10NOV2014 09NOV2019
102 BANKER 01MAY2013 09DEC2020
103 BROKER 14MAY2011 04MAY2018
;
RUN;
DATE7.:-
DATA E_14;
INFILE DATALINES;
INPUT EMP_ID DES $:10. JDATE RDATE;
INFORMAT JDATE RDATE DATE7.;
DATALINES;
101 BAKER 10NOV14 09NOV19
102 BANKER 01MAY13 09DEC20
103 BROKER 14MAY11 04MAY18
;
RUN;
DATA E_10;
INFILE DATALINES;
INPUT EMP_ID DES $:10. JDATE RDATE;
INFORMAT JDATE RDATE ANYDTDTE.;
DATALINES;
101 BAKER 10/11/2014 09/11/2019
102 BANKER 01/05/2013 09/12/2020
103 BROKER 14/05/2011 04/05/2018
;
RUN;
DATA E_16;
INFILE DATALINES;
INPUT EMP_ID DES $:10. JDATE RDATE;
INFORMAT JDATE RDATE DATETIME.;
DATALINES;
101 BAKER 10NOV14:11:15:46 09NOV19:10:41:13
102 BANKER 01MAY13:02:08:16 09DEC20:01:06:52
103 BROKER 14MAY11:11:02:18 04MAY18:08:19:48
;
RUN;
TIME.: THIS FORMAT IS USED TO REPRESENT ELAPSED NUMBER OF SECOND
I.E, 00:00:00 ONWARDS
DATA E_18;
INFILE DATALINES;
INPUT EMP_ID DES $:10. TIME;
INFORMAT TIME TIME.;
DATALINES;
101 BAKER 10:12:18
102 BANKER 01:15:19
103 BROKER 08:56:45
;
RUN;
INFORMAT FOR DATE AND TIME
DATE7. 29JAN10
DATE9. 29JAN2010
DDMMYY8. 29/01/10,29-01-10,29:01:10
DDMMYY10. 29/01/2010,29-01-2010,29:01:2010
TIME. 10:30:20
DATETIME. 29JAN10:10:30:20
ANYDTDTE. IF THE DATA INFORMAT IS UNKNOWN
FORMAT
DATA E_13;
INFILE DATALINES;
INPUT EMP_ID DES $:10. JDATE RDATE;
FORMAT JDATE RDATE DATE9.;
DATALINES;
101 BAKER 5693 7412
102 BANKER 7856 9245
103 BROKER 7844 8546
;
RUN;
MISCELLANIOUS FORMATS
COMMAW. : THIS IS USED TO READ COMMAS AND OUTPUT THE RESULT WITH
COMMAS
DATA E_13;
INFILE DATALINES;
INPUT EMP_ID DES $:10. SALARY;
INFORMAT SALARY DOLLAR5.1;
DATALINES;
101 BAKER $30.1
102 BANKER $41.0
103 BROKER $14.0
;
RUN;
DATA E_14;
INFILE DATALINES;
INPUT EMP_ID DES $:10. SALARY;
INFORMAT SALARY DOLLAR6.2;
FORMAT SALARY DOLLAR6.2;
DATALINES;
101 BAKER $30.0
102 BANKER $41.0
103 BROKER $14.0
;
RUN;
DATA E_A;
INFILE DATALINES;
INPUT EMP_ID DES $:10. SALARY;
INFORMAT SALARY DOLLAR7.;
FORMAT SALARY DOLLAR7.;
DATALINES;
101 BAKER $30,212
102 BANKER $40,153
103 BROKER $17,123
;
RUN;
DATA E_15;
INFILE DATALINES;
INPUT EMP_ID DES $:10. SALARY;
INFORMAT SALARY COMMA6.;
DATALINES;
101 BAKER 300,00
102 BANKER 410,00
103 BROKER 14,00
;
RUN;
DATA E_16;
INFILE DATALINES;
INPUT EMP_ID DES $:10. SALARY;
INFORMAT SALARY COMMA6.;
FORMAT SALARY COMMA6.;
DATALINES;
101 BAKER 300,00
102 BANKER 410,00
103 BROKER 14,00
;
RUN;
ATTRIB STATEMENT
ATTRIB STATEMENT MUST START WITH THE WORD ATTRIB. ALL THE
FORMATS AND INFORMATS FOR A VARIABLE CAN BE WRITTEN IS A SINGLE
ATTRIB STATEMENT
DATA E_;
INFILE CARDS;
ATTRIB DOB INFORMAT= DDMMYY8. FORMAT= DATE9. SALARY INFORMAT=
DOLLAR6. FORMAT=DOLLAR6.;
INPUT EPID:5. NAME :$ 12. PROF :$8. DOB SALARY;
cards;
1001 SAMAMMAR Tester 16/10/19 $15,267
1002 JOSHSAMPANDA Analyst 12/01/14 $16,267
;
PROC FORMAT
DATA GROUP;
INPUT TEAM $ COLOR $ SEX $;
DATALINES;
MARSH R F
KING B M
LION G F
BEAR Y M
;
QUIT;
DATA GROUP1;
INPUT TEAM $ COLOR $ SEX $;
FORMAT COLOR $COL. SEX $GEN.;
DATALINES;
MARSH R F
KING B M
LION G F
BEAR Y M
;
QUIT;
OPERATORS TYPES
1.AND
2.OR
3.IN
4.NOT
5.NOT IN
6. BETWEEN
7.LIKE
DATA KEYS1;
INFILE DATALINES;
INPUT NAME $ SEX $ SUBJECT $:15. AGE MARKS HEIGHT WEIGHT;
DATALINES;
ELLEN M MATHEMATICS 15 66 153 55
SAM M ENGLISH 12 88 169 70
CRISTANA F SOCIAL 14 56 165 60
MARIA F SCIENCE 15 71 160 66
JOHN M FRENCH 13 45 154 64
VICTORIA F MATHEMATICS 11 57 159 71
BRITNEY F ARABIC 19 64 161 59
ABDUL M ENGLISH 13 47 162 54
VIKRAM M SOCIAL 17 47 144 72
ALISHA F FRENCH 18 22 166 74
ALISHA M FRENCH 18 22 166 74
MONA F ARABIC 11 87 156 45
WILLIAM M SCIENCE 16 55 161 77
ALISHA F FRENCH 18 22 66 74
ALBERTA F ENGLISH 14 61 162 71
;
RUN;
WHERE STATEMENT IS USED TO SELECT A SPECIFIC OBSERVATION
DATA E2_;
SET KEYS1;
IF AGE=16;
RUN;
DATA E1_;
SET KEYS1;
IF AGE=15 THEN SALARY=6000;
RUN;
DATA E3_;
SET KEYS1;
IF AGE IN(15:18) THEN SALARY=16000;
RUN;
DATA E4_;
SET KEYS1;
IF AGE IN(11:15) THEN SALARY=10000;
ELSE SALARY=15000;
RUN;
DATA E5_;
SET KEYS1;
IF AGE IN(11:13) THEN SALARY=16000;
ELSE IF AGE IN(14:16) THEN SALARY=20000;
ELSE IF AGE IN(17:19) THEN SALARY=35000;
RUN;
GO TO STATEMENT: THIS STATEMENT IS USED FOR WRITING CASE BLOCKS.
IF THE CONDITION IS TRUE THEN THE SPECIFIC CASE IS EXECUTED.
DATA E6_;
LENGTH COLOR $7.;
SET KEYS1;
IF AGE>=11 AND AGE<=13 THEN GO TO CASE1;
ELSE IF AGE>=14 AND AGE<=15 THEN GO TO CASE2;
ELSE IF AGE>=16 AND AGE<=19 THEN GO TO CASE3;
CASE1: SALARY=5000;
COLOR='RED';
RETURN;
CASE2: SALARY=10000;
COLOR='PINK';
RETURN;
CASE3: SALARY=30000;
COLOR='YELLOW';
RETURN;
RUN;
ITERATIVE DO LOOPS
1.DO LOOP
2.DO WHILE
3.DO UNTIL
DO LOOP:
DATA A1_;
DO I=1 TO 5;
OUTPUT;
END;
RUN;
DATA SET2;
SUM = 0;
R = 1;
DO UNTIL(R>5);
SUM = SUM+R;
R+1;
END;
RUN;
CANCATENATION
DATA SPORTS;
INPUT TEAM $ NAME $ SCORE $;
DATALINES;
US SAM A+
US JOHN B-
US PELO A
UK JEM O
UK MOUZ C
UK BEZA A
;
RUN;
DATA SPORTS1;
INPUT TEAM $ NAME $ SCORE $;
DATALINES;
NZ RAZ C-
NZ MAZ A-
NZ REN C+
CA BEN A+
CA LEE B+
;
RUN;
DATA FINAL1;
SET SPORTS SPORTS1;
RUN;
DATA SPORTS2;
INPUT TEAM $ NAME $ RATING $ POINTS;
DATALINES;
US SAM A+ 1
US JOHN B- 2
US PELO A 3
UK JEM O 4
UK MOUZ C 1
UK BEZA A 6
;
RUN;
DATA SPORTS3;
INPUT TEAM $ NAME $ RATING $ POINTS $;
DATALINES;
NZ RAZ C- 5
NZ MAZ A- 2
NZ REN C+ 4
CA BEN A+ 1
CA LEE B+ 2
;
RUN;
DATA SPORTS2A;
INPUT TEAM $ NAME $ RATING $ POINTS FROM$;
DATALINES;
US SAM A+ 1 LA
US JOHN B- 2 SF
US PELO A 3 NY
UK JEM O 4 BATH
UK MOUZ C 1 YORK
UK BEZA A 6 OXFORD
;
RUN;
DATA SPORTS3A;
INPUT TEAM $ NAME $ RATING $ POINTS FROM $12.;
DATALINES;
NZ RAZ C- 5 QUEENSTOWN
NZ MAZ A- 2 CHRISTCHURCH
NZ REN C+ 4 WIINGTON
CA BEN A+ 1 QUBEC
CA LEE B+ 2 MONTREL
;
RUN;
IN THE BELOW PROGRAM THE ‘FROM’ VARIABLE GETS TRUNCATED. TO
AVOID THIS LENGTH STATEMENT SHOULD BE WRITTEN. ALWAYS IT SHOULD
BE WRITTEN BEFORE THE SET STATEMENT.
DATA SPORTS3B;
RETAIN TEAM NAME RATING POINTS FROM;
LENGTH FROM $12.;
SET SPORTS2A SPORTS3A;
RUN;
DATA SPORTS4;
SET SPORTS2 SPORTS3;
RUN;
DATA SPORTS5(RENAME=(K=POINTS));
SET SPORTS3;
K=INPUT(POINTS, 3.);
DROP POINTS;
RUN;
DATA SPORTS6;
SET SPORTS2 SPORTS5;
RUN;
DATA SPORTS7;
INPUT TEAM $ NAME $ RATING $ ;
DATALINES;
US SAM A+
US JOHN B-
US PELO A
UK JEM O
UK MOUZ C
UK BEZA A
;
RUN;
DATA SPORTS8;
INPUT TEAM $ NAME $ RATING $ POINTS $;
DATALINES;
NZ RAZ C- 5
NZ MAZ A- 2
NZ REN C+ 4
CA BEN A+ 1
CA LEE B+ 2
;
RUN;
EVEN WHEN THE VARIABLES ARE NOT PRESENT IN THE ANY OF THE
DATASETS IT CAN BE CANCATENATED.
DATA SPORTS9;
SET SPORTS7 SPORTS8;
RUN;
DATA SPORTS10;
INPUT TEAM $ NAME $ RATING $ COLOR $ ;
DATALINES;
US SAM A+ GREEN
US JOHN B- PINK
US PELO A BLUE
UK JEM O BLACK
UK MOUZ C BROWN
UK BEZA A RED
;
RUN;
DATA SPORTS11;
INPUT TEAM $ NAME $ RATING $ POINTS $;
DATALINES;
NZ RAZ C- 5
NZ MAZ A- 2
NZ REN C+ 4
CA BEN A+ 1
CA LEE B+ 2
;
RUN;
DATA SPORTS12;
SET SPORTS11 SPORTS10;
RUN;
PROC SORT
DATA STANDARD;
INFILE DATALINES;
INPUT NAME $ SEX $ SUBJECT $:15. AGE MARKS HEIGHT WEIGHT;
DATALINES;
ELLEN M MATHEMATICS 15 66 153 55
SAM M ENGLISH 12 88 169 70
CRISTANA F SOCIAL 14 56 165 60
MARIA F SCIENCE 15 71 160 66
JOHN M FRENCH 13 45 154 64
VICTORIA F MATHEMATICS 11 57 159 71
BRITNEY F ARABIC 19 64 161 59
ABDUL M ENGLISH 13 47 162 54
VIKRAM M SOCIAL 17 47 144 72
ALISHA F FRENCH 18 22 166 74
MONA F ARABIC 11 87 156 45
WILLIAM M SCIENCE 16 55 161 77
ALBERTA F ENGLISH 14 61 162 71
;
RUN;
OUT: THIS OPTION IS USED TO STORE THE SORTED DATA.IF OUT OPTION
IS NOT USED THE DATA GETS SORTED AND STORED IN THE MASTER
DATASET ITSELF.
DATA STAND;
INFILE DATALINES;
INPUT NAME $ SEX $ SUBJECT $:15. AGE MARKS HEIGHT WEIGHT;
DATALINES;
ELLEN M MATHEMATICS 15 66 153 55
SAM M ENGLISH 12 88 169 70
CRISTANA F SOCIAL 14 56 165 60
MARIA F SCIENCE 15 71 160 66
JOHN M FRENCH 13 45 154 64
VICTORIA F MATHEMATICS 11 57 159 71
BRITNEY F ARABIC 19 64 161 59
ABDUL M ENGLISH 13 47 162 54
VIKRAM M SOCIAL 17 47 144 72
ALISHA F FRENCH 18 22 166 74
ALISHA F FRENCH 18 22 166 74
MONA F ARABIC 11 87 156 45
WILLIAM M SCIENCE 16 55 161 77
ALISHA F FRENCH 18 22 166 74
ALBERTA F ENGLISH 14 61 162 71
;
RUN;
DATA KEY1;
INFILE DATALINES;
INPUT NAME $ SEX $ SUBJECT $:15. AGE MARKS HEIGHT WEIGHT;
DATALINES;
ELLEN M MATHEMATICS 15 66 153 55
SAM M ENGLISH 12 88 169 70
CRISTANA F SOCIAL 14 56 165 60
MARIA F SCIENCE 15 71 160 66
JOHN M FRENCH 13 45 154 64
VICTORIA F MATHEMATICS 11 57 159 71
BRITNEY F ARABIC 19 64 161 59
ABDUL M ENGLISH 13 47 162 54
VIKRAM M SOCIAL 17 47 144 72
ALISHA F FRENCH 18 22 166 74
ALISHA M FRENCH 18 22 166 74
MONA F ARABIC 11 87 156 45
WILLIAM M SCIENCE 16 55 161 77
ALISHA F FRENCH 18 22 66 74
ALBERTA F ENGLISH 14 61 162 71
;
RUN;
DATA SPORTZ1;
INPUT TEAM $ NAME $ RATING $ ;
DATALINES;
US SAM A+
US JOHN B-
US PELO A
UK JEM O
UK MOUZ C
UK BEZA A
;
RUN;
DATA SPORTZ2;
INPUT TEAM $ NAME $ RATING $;
DATALINES;
NZ RAZ C-
NZ MAZ A-
NZ REN C+
CA BEN A+
CA LEE B+
;
RUN;
DATA SPROTSZ3;
SET SPORTZ1 SPORTZ2;
BY TEAM;
RUN;
DATA SPORTZ4;
SET SPORTZ1 SPORTZ2;
BY TEAM;
IF FIRST.TEAM=1 THEN OUTPUT;
RUN;
DATA SPORTZ5;
SET SPORTZ1 SPORTZ2;
BY TEAM;
IF LAST.TEAM=1 THEN OUTPUT;
RUN;
DATA SPORTZ7;
SET SPORTZ1 SPORTZ2;
BY TEAM;
IF FIRST.TEAM=1 AND LAST.TEAM=1 THEN OUTPUT;
RUN;
MERGING
DATA CARS;
INPUT MFG $ MODEL $ MILEAGE_MPS $;
DATALINES;
BENZ B-CLASS 12
BMW X6 15
SUZUKI WINZ 16
ISUZ MUX 14
;
RUN;
DATA LEFT;
MERGE MFG(IN=A) CARS(IN=B);
BY MFG;
IF A;
RUN;
RIGHT MERGE
DATA RIGHT;
MERGE MFG(IN=A) CARS(IN=B);
BY MFG;
IF B;
RUN;
INNER MERGE
DATA INNER;
MERGE MFG(IN=A) CARS(IN=B);
BY MFG;
IF A AND B;
RUN;
FULL MERGE
DATA FULL;
MERGE MFG(IN=A) CARS(IN=B);
BY MFG;
IF A OR B;
RUN;
PROC APPEND
DATA SPORTS1Z;
INPUT TEAM $ NAME $ SCORE $;
DATALINES;
US SAM A+
US JOHN B-
US PELO A
UK JEM O
UK MOUZ C
UK BEZA A
;
RUN;
DATA SPORTS2Z;
INPUT TEAM $ NAME $ SCORE $;
DATALINES;
NZ RAZ C-
NZ MAZ A-
NZ REN C+
CA BEN A+
CA LEE B+
;
RUN;
DATA PLAYERS;
INPUT TEAM $ NAME $ SCORE $;
LABEL TEAM='GROUP' NAME='PLAYERS' SCORE='CREDITS';
RUN;
DATA SPORTS3Z;
INPUT TEAM $ NAME $ SCORE $;
DATALINES;
US SAM 1
US JOHN 1
US PELO 2
UK JEM 1
UK MOUZ 2
UK BEZA 2
;
RUN;
DATA SPORTS4Z;
INPUT TEAM $ NAME $ SCORE ;
DATALINES;
NZ RAZ 1
NZ MAZ 0
NZ REN 2
CA BEN 1
CA LEE 2
;
RUN;
NUMERIC FUNTIONS:
DATA M_2;
A=2.122654;
ROU1=ROUND(A,0.1);
ROU2=ROUND(A,0.01);
ROU3=ROUND(A,0.001);
ROU4=ROUND(A,0.0001);
RUN;
DATA M_3;
A=1.236;
B=-1.236;
Z=1.6;
X=-1.8;
F1=FLOOR(A);
C1=CEIL(A);
I1=INT(A);
F2=FLOOR(B);
C2=CEIL(B);
I2=INT(B);
F3=FLOOR(Z);
C3=CEIL(Z);
I3=INT(Z);
F4=FLOOR(X);
C4=CEIL(X);
I4=CEIL(X);
RUN;
SQRT FUNCTION: THIS FUNCTION IS USED FOR FINDING THE SQUARE ROOT
OF THE GIVEN NUMBER.
DATA SQ;
A=25;
S=SQRT(A);
RUN;
DATA REM1;
A=3;
REMINDER=MOD(A,2);
RUN;
DATA DD;
INPUT SALES $ REVENUE;
DATALINES;
SAL1 200
SAL2 320
SAL3 120
SAL4 250
SAL5 200
SAL6 512
;
RUN;
DATA M_4;
SET DD;
K=DIF(REVENUE);
RUN;
LAG FUNCTION: IT TRANSFER THE VALUE FROM ABOVE OBSERVATON TO
BELOW OBSERVATION
DATA DD1;
SET DD;
LP=LAG(REVENUE);
RUN;
DATA DD2;
SET DD;
DIFF=DIF(REVENUE);
LP=LAG(REVENUE);
RESULT=REVENUE-LP;
RUN;
DATA DD3;
SET DD;
IF REVENUE >LAG(REVENUE) THEN PROFIT_LOSS='INCREASED';
ELSE PROFIT_LOSS='DECREASED';
RUN;
DATA DD4;
INPUT SUBJECT $ MARKS1-MARKS3;
DATALINES;
MATHS 10 12 13
ANTRO 19 10 25
PHYSC 21 15 13
SOCIO 10 12 3
REGIA 12 5 6
;
RUN;
DATA DD5;
SET DD4;
MINIMUM=MIN(MARKS1,MARKS2,MARKS3);
MAXIMUM=MAX(MARKS1,MARKS2,MARKS3);
TOTAL=SUM(MARKS1,MARKS2,MARKS3);
AVERAGE=MEAN(MARKS1,MARKS2,MARKS3);
STD_DEV=STD(MARKS1,MARKS2,MARKS3);
MED=MEDIAN(MARKS1,MARKS2,MARKS3);
RUN;
PUT: THIS STATEMENT IS USED FOR VIEWING THE RESULT IN THE LOG
WINDOW.
CHARACTER FUNCTIONS
DATA _NULL_;
A='THIS IS SAS PROGRAM HELLO!!!!!!! WORLD.';
INDEX1=INDEX(A,'O');
PUT @5 'THE POSITION OF THE CHARACTER IS:' INDEX1;
RUN;
DATA _NULL_;
A='THIS IS SAS PROGRAM HELLO!!!!!!! WORLD.';
INDEX1=INDEXC(A,'HELLO');
PUT @5 'THE POSITION OF THE CHARACTER IS:' INDEX1;
RUN;
DATA _NULL_;
DATA _NULL_;
A='THIS IS SAS PROGRAM HELLO!!!!!!! WORLD.';
INDEX1=INDEXC(A,'HELLO');
PUT @5 'THE POSITION OF THE CHARACTER IS:' INDEX1;
RUN;
DATA _NULL_;
A= 'BC1-09A';
NA=NOTALPHA(A);
NAN=NOTALNUM(A);
PUT @5 'THE POSITION OF NONALPHABETIC CHARACTERS:' NA;
PUT @5 'THE POSITION OF NONALPHABETIC AND NON NUMERIC
CHARACTERS:' NAN;
RUN;
DATA _NULL_;
A='THIS IS SAS PROGRAM HELLO!!!!!!! WORLD.';
FIND1=FIND(A,'O',16);
PUT @5 'THE POSITION OF THE CHARACTER:' FIND1;
RUN;
DATA _NULL_;
A='THIS IS SAS PROGRAM HELLO!!!!!!! WORLD.';
FIND1=FIND(A,'O');
PUT @5 'THE POSITION OF THE CHARACTER:' FIND1;
RUN;
DATA _NULL_;
A='THIS IS SAS PROGRAM HELLO !!!!!!! WORLD.';
FINDC1=FINDC(A,'D',16);
FINDW1=FINDW(A,'HELLO',10);
PUT @5 'THE POSITION OF THE CHARACTER:' FINDC1;
PUT @5 'THE POSITION OF THE CHARACTER:' FINDW1;
RUN;
DATA _NULL_;
A='THIS IS SAS PROGRAM HELLO!!!!!!! WORLD.';
LENGTH1=LENGTH(A);
PUT @5 'THE LENGTH OF THE STRING IS:' LENGTH1;
RUN;
DATA _NULL_;
A= 'AMERICA';
LENGTH1=LENGTH(A);
PUT @5 'THE LENGTH OF THE STRING IS:' LENGTH1;
RUN;
DATA US1;
A='THIS IS SAS PROGRAMMING';
B='';
LEN1= LENGTHN(A);
LEN2=LENGTH(A);
LEN3=LENGTHN(B);
LEN4=LENGTH(B);
RUN;
DATA _NULL_;
A= 'AMERICA USA CANADA AMERICA JAPAN MEXICO AMERICA';
CASE=PROPCASE(A);
PUT @5 CASE;
RUN;
DATA _NULL_;
A= 'AMERICA USA CANADA AMERICA JAPAN MEXICO AMERICA';
CASE=LOWCASE(A);
PUT @5 CASE;
RUN;
DATA _NULL_;
A=' AMERICA USA CANADA AMERICA JAPAN MEXICO AMERICA';
CASE=UPCASE(A);
PUT @5 CASE;
RUN;
DATA _NULL_;
A='AMERICA USA CANADA AMERICA JAPAN MEXICO AMERICA';
REV=REVERSE(A);
PUT @5 REV;
RUN;
DATA _NULL_;
A='AMERICA USA CANADA AMERICA JAPAN MEXICO AMERICA';
TRANS1=TRANSLATE(A,'Z', 'A');
PUT @5 TRANS1;
RUN;
DATA _NULL_;
A='AMERICA USA CANADA AMERICA JAPAN MEXICO AMERICA';
TRANS1=TRANWRD(A,'AMERICA', 'SINGAPORE');
PUT @5 TRANS1;
RUN;
DATA _NULL_;
A='THIS IS A SAS PROGRAM CREATED';
EXTRACTED=SUBSTR(A,15,14);
PUT @5 'THE OUTPUT IS:' EXTRACTED;
RUN;
DATA _NULL_;
A='THIS IS A SAS PROGRAM CREATED';
EXTRACTED=SUBSTR(A,4,9);
PUT @5 'THE OUTPUT IS:' EXTRACTED;
RUN;
DATA _NULL_;
A='BANANAS, ORANGES & MANGOS ARE DELICIOUS FRUITS';
EXTRACTED=SCAN(A,1,'&');
PUT @5 'THE OUTPUT IS:' EXTRACTED;
RUN;
DATA _NULL_;
A='BANANAS, ORANGES & MANGOS ARE DELICIOUS FRUITS';
EXTRACTED=SCAN(A,-2);
PUT @5 'THE OUTPUT IS:' EXTRACTED;
RUN;
DATA _NULL_;
A='AMERICAN EXPRESS';
B=' TIMINGS 9.30 AM';
CANCAT= A||B;
PUT @5 CANCAT;
RUN;
DATA _NULL_;
A='AMERICAN EXPRESS';
COMP=COMPBL(A);
PUT @5 COMP;
RUN;
CANCATENATION FUNCTIONS: TH
DATA CAT1;
X=' THE ';
Y=' AMERICAN ';
A=CAT(X,Y);* CAT:IT CANCATENATES THE STRINGS WITHOOUT REMOVING
THE LEADING AND TRAILING SPACES;
B=CATT(X,Y);*CATT: IT REMOVES THE TRAILING SPACES AND JOINS THE
STRINGS;
RUN;
DATA COMP12;
STRING='STUDING AMERICAN HISTORY AT BLOG !.... 12345';
RUN;
DATA COMP13;
SET COMP12;
STRING1=COMPRESS(STRING," "); REMOVES SPACE
RUN;
DATA COMP14;
SET COMP12;
STRING1=COMPRESS(STRING,' ','AK'); KEEPS ONLY ALPHABETS
RUN;
DATA COMP15;
SET COMP12;
STRING1=COMPRESS(STRING,' ','D'); COMPRESS ONLY DIGITS
RUN;
DATA COMP16;
SET COMP12;
STRING1=COMPRESS(STRING,' ','L'); COMPRESS ONLY LOWERCASE
ALPHABETS
RUN;
DATA COMP17;
SET COMP12;
STRING1=COMPRESS(STRING,' ','U'); COMPRESS ONLY UPPERCASE
ALPHABETS
RUN;
DATA COMP22;
SET COMP12;
STRING1=COMPRESS(STRING,' ','A'); COMPRESS ONLY ALPHABETS
RUN;
DATA COMP18;
SET COMP12;
STRING1=COMPRESS(STRING,'S','K'); KEEPS ONLY SPECIFIED ALPHABETS
HERE CAPITAL S
RUN;
DATA COMP19;
SET COMP12;
STRING1=COMPRESS(STRING,'!'); KEEPS ONLY !
RUN;
DATA COMP20;
SET COMP12;
STRING1=COMPRESS(STRING,' ','P'); COMPRESSES PUNCTUATION
RUN;
DATA COMP21;
SET COMP12;
STRING1=COMPRESS(STRING,'S','I'); COMPRESS ALPHABET SPECIFIED
RUN;
DATE FUNCTIONS
DATA F_1;
INFILE DATALINES;
INPUT EMP_ID DES $:10. JDATE RDATE;
INFORMAT JDATE DATETIME. RDATE DATE9. ;
FORMAT JDATE DATETIME. RDATE DATE9.;
DATALINES;
101 BAKER 10NOV2014:01:12:15 09NOV2019
102 BANKER 01MAY2013:02:15:59 09DEC2020
103 BROKER 14MAY2011:12:19:57 04MAY2018
;
RUN;
DATA F_2;
SET F_1;
SEC=SECOND(JDATE);
RUN;
DATA F_7;
SET F_1;
MTH=MONTH(RDATE);
RUN;
DATA F_9;
SET F_1;
DPART=DATEPART(JDATE);
FORMAT DPART DATE9.;
RUN;
DATA F_10;
SET F_1;
TPART=TIMEPART(JDATE);
FORMAT TPART TIME.;
RUN;
DATA F_15;
INFILE DATALINES;
INPUT EMP_ID DES $:10. JDATE RDATE;
INFORMAT JDATE DATE9. RDATE DATE9. ;
FORMAT JDATE DATE9. RDATE DATE9.;
DATALINES;
101 BAKER 10NOV2015 09NOV2019
102 BANKER 01MAY2013 09DEC2020
103 BROKER 14MAY2011 04MAY2018
;
RUN;
DATA F_16;
SET F_15;
INT1=INTCK('YEAR',JDATE,RDATE);
RUN;
DATA F_18;
SET F_15;
INT1=INTCK('YEARS',JDATE,RDATE,'D');
RUN;
DATA F_19;
SET F_15;
INT1=INTCK('MONTHS',JDATE,RDATE);
RUN;
DATA F_20;
SET F_15;
INT1=INTCK('WEEKS',JDATE,RDATE);
RUN;
DATA F_22;
SET F_15;
INT1=INTCK('DAYS',JDATE,RDATE);
RUN;
DATA TRIM1;
INFILE DATALINES;
INPUT A $ B $ 4-12 C $;
TM= TRIM(A)|| TRIM(B) || C; *TRIM- PUTS ONE BLANK SPACE WHEN THE
VARIABLE IS MISSING;
TN= TRIMN(A)|| TRIMN(B)|| C; *TRIMN - DOESNT LEAVE ANY SPACE
BETWEEN THE VARIABLES EVEN ITS MISSING;
DATALINES;
THE ALASKAN BIRD
THE BIRD
;
RUN;
MISCELANEOUS FUNTIONS
DATA _NULL_;
IF EXIST('WORK.SUN')=1 THEN PUT@5 'DATASET EXISTS...';
ELSE PUT @5 "DATASET DOESN'T EXISTS";
RUN;
DATA _NULL_;
IF EXIST('WORK.SUN')=1 THEN DO;
OPENING=OPEN('WORK.SUN') ;
VAR=ATTRN(OPENING,'NVAR');
OBS=ATTRN(OPENING,'NOBS');
CS=CLOSE(OPENING);
PUT @10 'DATASET EXISTS, THE VARIABLES AND OBSERVATIONS
ARE: 'VAR'AND'OBS'';
END;
ELSE PUT @10 "DATASET DOESN'T EXIST";
RUN;
DATA SUN;
INFILE DATALINES;
INPUT NAME $ SEX $ SUBJECT $:15. AGE MARKS HEIGHT WEIGHT;
DATALINES;
ELLEN M MATHEMATICS 15 66 153 55
SAM M ENGLISH 12 88 169 70
CRISTANA F SOCIAL 14 56 165 60
MARIA F SCIENCE 15 71 160 66
JOHN M FRENCH 13 45 154 64
VICTORIA F MATHEMATICS 11 57 159 71
BRITNEY F ARABIC 19 64 161 59
ABDUL M ENGLISH 13 47 162 54
VIKRAM M SOCIAL 17 47 144 72
ALISHA F FRENCH 18 22 166 74
ALISHA M FRENCH 18 22 166 74
MONA F ARABIC 11 87 156 45
WILLIAM M SCIENCE 16 55 161 77
ALISHA F FRENCH 18 22 66 74
ALBERTA F ENGLISH 14 61 162 71
;
RUN;
DATA K_1;
SET SUN;
M=PUT(MARKS,$12.);
RUN;
STATEMENT OPTIONS
DATA STANDARD;
INFILE DATALINES;
INPUT NAME $ SEX $ SUBJECT $:15. AGE MARKS HEIGHT WEIGHT;
DATALINES;
ELLEN M MATHEMATICS 15 66 153 55
SAM M ENGLISH 12 88 169 70
CRISTANA F SOCIAL 14 56 165 60
MARIA F SCIENCE 15 71 160 66
JOHN M FRENCH 13 45 154 64
VICTORIA F MATHEMATICS 11 57 159 71
BRITNEY F ARABIC 19 64 161 59
ABDUL M ENGLISH 13 47 162 54
VIKRAM M SOCIAL 17 47 144 72
ALISHA F FRENCH 18 22 166 74
MONA F ARABIC 11 87 156 45
WILLIAM M SCIENCE 16 55 161 77
ALBERTA F ENGLISH 14 61 162 71
;
RUN;
DATA STANDARD5;
MODIFY STANDARD5;
IF SEX='F' THEN REMOVE;
RUN;
DATA STAND_3;
SET STANDARD;
IF SEX='M' THEN OUTPUT;
RUN;
DATASET OPTION
PROC OPTION
THESE OPTIONS ARE USED GLOBALLY THROUGH OUT THE SAS ENVIRNOMENT.
WITH THE BELOW PROGRAM ALL THE OPTIONS ARE DISPLAYED IN THE LOG
WINDOW.
PROC OPTIONS;
RUN;
UPTO THE ABOVE PROGRAM ALL THE OPTIONS AND THEIR GROUP IS CODED.
NOW LETS SEE HOW TO USE THE OPTIONS GLOBALLY.
ARRAYS ARE OF TWO TYPES THEY ARE ONE DIMENSIONAL ARRAYS AND TWO
DIMENSIONAL ARRAYS
DATA FRUITS1;
SET FRUITS;
ARRAY FRUIT[3] GRADE1 GRADE2 GRADE3;
DO P=1 TO 3;
IF FRUIT[P]=' ' THEN FRUIT[P]='-';
END;
DROP P;
RUN;
IN THE ABOVE PROGRAM ARRAY SHOULD START WITH ARRAY STATEMENT
FOLLOWED BY ARRAY NAME (ARRAY FRUIT AND [3] REPRESENTS NUMBER OF
VARIABLES. THEN FOLLOWED BY 3 VARIABLES.
DATA SUB;
INPUT N1 $ N2 $ N3 $ N4 $ N5 $;
DATALINES;
BEN RAM SAM RON ANASA
BILL JAMES CHRIS GLEN VIDH
BRUZ ELLE SAMG JENNY RUBEN
;
RUN;
DATA MATCHING;
INPUT COLORS1 $ COLORS2 $ COLORS3 $ COLORS4 $ COLORS5 $;
DATALINES;
WHITE BROWN GREEN YELLOW PINK
ORANGE RED GREEN PINK YELLOW
BROWN BROWN YELLOW YELLOW PINK
BROWN YELLOW RED PINK WHITE
;
RUN;
DATA RESULTS;
SET MATCHING;
ARRAY COLO(*)$ COLORS1-COLORS5;
ARRAY MATCHING(5)$ _TEMPORARY_('BROWN', 'BROWN', 'YELLOW',
'YELLOW','PINK');
DO O=1 TO DIM(MATCHING);
IF COLO(O)=MATCHING(O);
END;
DROP O;
RUN;
DATA VAL;
SET EXAM;
C=0;
ARRAY RES(*) $ O1-O6 ;
ARRAY ANS(6) $ _TEMPORARY_ ('A','B','B','C','A','A');
DO I=1 TO DIM(ANS);
IF RES(I)='' THEN C=C-1;
IF RES(I)=ANS(I) THEN DO;
C=C+1;
END;
END;
DROP I;
RUN;
TWO DIMENSIONAL ARRAYS WORK COLUMN WISE FIRST THEN ROW WISE.
DATA PRICES;
INPUT COD $ U1-U3/U4-U6;
ARRAY MARK(2,3) U1-U6;
DO I=1 TO 2;
DO J=1 TO 3;
MARK (I,J)=ROUND(MARK(I,J), 0.1);
END;
END;
DROP I J;
CARDS;
P101 23.45 22.56 26.23
26.23 24.34 25.67
P102 45.23 45.64 46.12
47.89 48.23 49.34
P103 56.87 57.34 58.32
59.34 58.12 59.32
;
IMPORTING AND EXPORTING THE DATA
TO GET THE SPECIFIED EXCEL SHEET AMONG THE GROUP OF EXCEL SHEETS
WE USE SHEET STATEMENT.
PROC IMPORT DATAFILE="C:\USERS\RICKY\DESKTOP\FBA AMAZON.XLS"
OUT=WORK.B
DBMS=XLS
REPLACE;
GETNAMES=NO;
SHEET='AMAZON_FBA_SALES';
RUN;
DATA KEYS;
INFILE DATALINES;
INPUT NAME $ SEX $ SUBJECT $:15. AGE MARKS HEIGHT WEIGHT;
DATALINES;
ELLEN M MATHEMATICS 15 66 153 55
SAM M ENGLISH 12 88 169 70
CRISTANA F SOCIAL 14 56 165 60
MARIA F SCIENCE 15 71 160 66
JOHN M FRENCH 13 45 154 64
VICTORIA F MATHEMATICS 11 57 159 71
BRITNEY F ARABIC 19 64 161 59
ABDUL M ENGLISH 13 47 162 54
VIKRAM M SOCIAL 17 47 144 72
ALISHA F FRENCH 18 22 166 74
ALISHA M FRENCH 18 22 166 74
MONA F ARABIC 11 87 156 45
WILLIAM M SCIENCE 16 55 161 77
ALISHA F FRENCH 18 22 66 74
ALBERTA F ENGLISH 14 61 162 71
;
RUN;
DATA E_10;
INFILE DATALINES;
INPUT EMP_ID DES $:10. JDATE RDATE;
INFORMAT JDATE RDATE DDMMYY10.;
DATALINES;
101 BAKER 10/11/2014 09/11/2019
102 BANKER 01/05/2013 09/12/2020
103 BROKER 14/05/2011 04/05/2018
;
RUN;
DATA E_11;
INFILE DATALINES;
INPUT EMP_ID: $ DES $:10. JDATE RDATE;
INFORMAT JDATE DATE7. RDATE DDMMYY10.;
FORMAT JDATE DATE7. RDATE DDMMYY10.;
LABEL JDATE='JOINING DATE';
DATALINES;
101 BAKER 10NOV14 09/11/2019
102 BANKER 01MAY13 09/12/2020
103 BROKER 14MAY11 04/05/2018
104 ATTORNEY 10MAR10 06/04/2017
105 DOCTOR 11JUN12 06/04/2013
;
RUN;
DATA E_14;
INFILE DATALINES;
INPUT EMP_ID DES $9-15 JDATE RDATE;
INFORMAT JDATE RDATE DATE7.;
DATALINES;
101 BAKER 10NOV15 09NOV19
102 BANKER 01MAY13 09DEC20
103 BROKER 14MAY11 04MAY18
;
RUN;
DATA E_11B;
INFILE DATALINES;
INPUT EMP_ID: $ DES $:10. JDATE RDATE;
INFORMAT JDATE DATE7. RDATE DDMMYY10.;
FORMAT JDATE DATE7. RDATE DDMMYY10.;
LABEL JDATE='JOINING DATE';
DATALINES;
101 BAKER 10NOV14 09/11/2019
102 BANKER 01MAY13 09/12/2020
103 BROKER 14MAY11 04/05/2018
104 ATTORNEY 10MAR10 06/04/2017
105 DOCTOR 11JUN12 06/04/2013
;
RUN;
RUN;
PROC TRANSPOSE
DATA PROFILE;
INFILE DATALINES;
INPUT NAME $ SEX $ SUBJECT $:15. AGE MARKS HEIGHT WEIGHT;
DATALINES;
ELLEN M MATHEMATICS 15 66 153 55
SAM M ENGLISH 12 88 169 70
CRISTANA F SOCIAL 14 56 165 60
MARIA F SCIENCE 15 71 160 66
JOHN M FRENCH 13 45 154 64
VICTORIA F MATHEMATICS 11 57 159 71
BRITNEY F ARABIC 19 64 161 59
ABDUL M ENGLISH 13 47 162 54
VIKRAM M SOCIAL 17 47 144 72
ALISHA F FRENCH 18 22 166 74
MONA F ARABIC 11 87 156 45
WILLIAM M SCIENCE 16 55 161 77
ALBERTA F ENGLISH 14 61 162 71
;
RUN;
SYNTAX:
PROC MEANS DATA=DATASET_NAME;
VAR VARIABLES
RUN;
DATA RACING;
INPUT RACER $ 5-14 BIKE $ 15-33 DISTANCE TIME_MIN;
DATALINES;
MIKE MV Agusta F3 326 15
ROGER Kawasaki 300 25
ELLON KTM RC250 312 19
JAMES Aprilia RSV4 RF 253 45
JACK CHI Ducati Panigale R 340 8
;
RUN;
data profile;
infile datalines;
input Name $ Sex $ Subject $:15. Age Marks Height Weight;
datalines;
Ellen M Mathematics 15 66 153 55
Sam M English 12 88 169 70
cristana F Social 14 56 165 60
Maria F Science 15 71 160 66
John M French 13 45 154 64
Victoria F Mathematics 11 57 159 71
Britney F Arabic 19 64 161 59
Abdul M English 13 47 162 54
Vikram M Social 17 47 144 72
Alisha F French 18 22 166 74
Mona F Arabic 11 87 156 45
William M Science 16 55 161 77
Alberta F English 14 61 162 71
;
run;
DATA SCORES;
INPUT NAME $ SUBJECT $ MARKS1-MARKS3;
DATALINES;
SAM MATHS 10 12 13
PARVEZ ANTRO 19 10 25
ENNA PHYSC 21 15 13
ESKANA SOCIO 10 12 3
REGIA SCIENCE 12 5 6
;
RUN;
VARIABLES GROUPING
VARIABLES ARE GROUPED IN TWO TYPES.
1.GROUPING VARIABLES
2.CALCULATION VARIABLES
EXAMPLE.
DATA STANDARD;
INFILE DATALINES;
INPUT NAME $ SEX $ SUBJECT $&15. AGE MARKS HEIGHT WEIGHT;
DATALINES;
ELLEN M MATHEMATICS 15 66 153 55
SAM M ENGLISH 12 88 169 70
CRISTANA F SOCIAL STUDIES 14 56 165 60
MARIA F GENERAL SCIENCE 15 71 160 66
JOHN M FRENCH 13 45 154 64
VICTORIA F MATHEMATICS 11 57 159 71
BRITNEY F ARABIC 19 64 161 59
ABDUL M ENGLISH 13 47 162 54
VIKRAM M SOCIAL STUDIES 17 47 144 72
ALISHA F FRENCH 18 22 166 74
MONA F ARABIC 11 87 156 45
WILLIAM M GENERAL SCIENCE 16 55 161 77
ALBERTA F ENGLISH 14 61 162 71
;
RUN;
PROC REPORT;
RUN;
OPTIONS
BOX: THIS OPTION IS USED FOR CREATING THE BOX IN THE OUTPUT
WINDOW
PROC REPORT DATA=STANDARD BOX;
RUN;
PAGESIZE OR PS: THIS OPTION IS USED FOR EXPANDING THE PAGE SIZE.
THE DEFAULT PAGESIZE IS 15 CAN BE EXTENDED TO 32,767. THIS
OPTION IS USED WHEN THE DATA IS VERY LARGE.
PROC REPORT DATA=STANDARD PS=68;
RUN;
STATEMENTS
COLUMN: THIS IS SIMILAR TO THE VAR STATEMENT OF THE PROC PRINT
WHERE IT HOLD THE VARIABLE NAMES
AND IN THE DESIRED ORDER.
PROC REPORT DATA=STANDARD;
COLUMN NAME SEX MARKS;
RUN;
EXAMPLES OF ANALYSIS
PROC REPORT DATA=STANDARD SPLIT='/' STYLE(COLUMN)=[JUST=CENTER];
COLUMN NAME SEX AGE MARKS HEIGHT WEIGHT;
DEFINE NAME/'STUDENT/NAME' WIDTH=18 SPACING=10 DISPLAY;
DEFINE SEX/'STUDENT/GENDER' WIDTH=15 SPACING=5 GROUP
FORMAT=$DARK.;
DEFINE AGE/'STUDENT AGE' ANALYSIS;
RUN;
EXAMPLES OF DESCENDING
PROC REPORT DATA=STANDARD SPLIT='/' STYLE(COLUMN)=[JUST=CENTER];
COLUMN NAME SEX AGE MARKS HEIGHT WEIGHT;
DEFINE NAME/'STUDENT/NAME' WIDTH=18 SPACING=10 DISPLAY;
DEFINE SEX/'STUDENT/GENDER' WIDTH=15 SPACING=5 GROUP
FORMAT=$DARK.;
DEFINE AGE/'STUDENT AGE' DESCENDING ;
RUN;
EXAMPLE OF ACROSS
PROC REPORT DATA=STANDARD SPLIT='/' STYLE(COLUMN)=[JUST=CENTER];
COLUMN NAME SEX AGE MARKS HEIGHT WEIGHT;
DEFINE NAME/'STUDENT/NAME' WIDTH=18 SPACING=10 DISPLAY;
DEFINE SEX/'STUDENT/GENDER' WIDTH=15 SPACING=5 GROUP
FORMAT=$DARK.;
DEFINE AGE/'STUDENT AGE' ACROSS;
RUN;
BREAK STATEMENT
BREAK STATEMENT IS DIVIDED INTO 3 CATEGORIES BREAK BEFORE,
BREAK AFTER, BREAK.
OL: DRAWS A LINE ABOVE THE SUMMARY. CHECK THE BELOW PROGRAM IN
THE OUTPUT WINDOW.
PROC REPORT DATA=STANDARD SPLIT='/' STYLE(COLUMN)=[JUST=CENTER];
COLUMN NAME SEX AGE MARKS HEIGHT WEIGHT;
DEFINE NAME/'STUDENT/NAME' DISPLAY;
DEFINE SEX/'STUDENT/GENDER' GROUP FORMAT=$DARK.;
DEFINE AGE/'STUDENT AGE' DISPLAY;
DEFINE MARKS/ ORDER ANALYSIS;
BREAK BEFORE SEX/SUMMARIZE OL;
RUN;
UL: DRAWS A LINE BELOW THE SUMMARY. CHECK THE BELOW PROGRAM IN
THE OUTPUT WINDOW.
PROC REPORT DATA=STANDARD SPLIT='/' STYLE(COLUMN)=[JUST=CENTER];
COLUMN NAME SEX AGE MARKS HEIGHT WEIGHT;
DEFINE NAME/'STUDENT/NAME' DISPLAY;
DEFINE SEX/'STUDENT/GENDER' GROUP FORMAT=$DARK.;
DEFINE AGE/'STUDENT AGE' DISPLAY;
DEFINE MARKS/ ORDER ANALYSIS;
BREAK BEFORE SEX/SUMMARIZE UL;
RUN;
DOL AND DUL: DRAWS A DOUBLE LINES ABOVE AND BELOW THE SUMMARY.
CHECK THE BELOW PROGRAM IN THE OUTPUT WINDOW.
PROC REPORT DATA=STANDARD;
COLUMN NAME SEX AGE MARKS HEIGHT WEIGHT;
DEFINE NAME/'STUDENT/NAME' DISPLAY;
DEFINE SEX/'STUDENT/GENDER' GROUP;
DEFINE AGE/'STUDENT AGE' DISPLAY;
DEFINE MARKS/ ORDER ANALYSIS;
BREAK BEFORE SEX/SUMMARIZE DOL DUL STYLE=[BACKGROUND=PINK
FOREGROUND=RED];
RUN;
COMPUTE STATEMENT:
IT IS ALMOST SIMILAR TO DO STATEMENT. HERE WE CAN PERFORM
ARTHEMATIC/STATISTICAL OPERATIONS AND SOME
CONDITIONAL STATEMENTS. COMPUTE STATEMENT STARTS WITH COMPUTE
AFTER,COMPUTE BEFORE A GROUP AND SHOULD
END WITH ENDCOMP STATEMENT. MUST BE WRITTEN BEFORE RUN
STATEMENT.WE CAN CREATE A NEW VARIABLE ALSO
PROC REPORT DATA=STANDARD;
COLUMN NAME SEX AGE MARKS HEIGHT WEIGHT;
DEFINE NAME/DISPLAY WIDTH=15;
DEFINE SEX/ GROUP;
DEFINE AGE/ DISPLAY;
DEFINE MARKS/ ANALYSIS;
DEFINE HEIGHT/DISPLAY;
DEFINE WEIGHT/DISPLAY;
BREAK AFTER SEX/SUMMARIZE;
RBREAK AFTER/SUMMARIZE;
COMPUTE AFTER SEX;
NAME='TOTAL';
ENDCOMP;
RUN;
TO CHECK THE MACRO VALUE IN THE LOG WINDOW WE HAVE TO USE %PUT
AND MACRO NAME SHOULD START WITH &.& REPRESENTS A MACRO
REFERENCE.
%LET VAR1=100;
%PUT THE VALUES OF THE MACRO IS:&VAR1;
IT IS A SIMPLE MACRO WHICH CAN BE USED GOBALLY.BY USING %LET WE
CAN CREATE MACRO WITH ONLY ONE VARIABLE.
COMPLEX MACRO:
%MACRO SORTTING(NAME,VARIABLE);
PROC SORT DATA=&NAME;
BY &VARIABLE;
RUN;
%MEND;
%SORTTING(E_11,EMP_ID);
%MACRO COMPLEX;
%LET PRICE=100;
%LET PRODUCT=TABLET;
%PUT THE PRICE IS &PRICE AND THE PRODUCT IS &PRODUCT;
%MEND;
%COMPLEX;THIS STATEMENT RESOLVES THE MACRO.
DATA RACE;
INPUT RACER $ 5-14 BIKE $ 15-33 DISTANCE TIME_MIN;
DATALINES;
MIKE MV Agusta F3 326 15
ROGER Kawasaki 300 25
ELLON KTM RC250 312 19
JAMES Aprilia RSV4 RF 253 45
JACK CHI Ducati Panigale R 340 8
;
RUN;
DATA CALCULATION2;
SET RACE;
TIME_SEC=60*&PRICE;
RUN;
EXAMPLE
%MACRO SPEED(DATSET,SOURCE,V1,Z1,VARIABLE);
DATA &DATSET;
SET &SOURCE;
&VARIABLE=&V1 &Z1;
RUN;
%MEND;
%SPEED(NEW,RACE,DISTANCE,TIME_MIN,SPEED);
EXAMPLE
%MACRO IMPORTING(PATH,DATANAME,FORMAT);
PROC IMPORT DATAFILE=&PATH
OUT=&DATANAME
DBMS=&FORMAT;
RUN;
%MEND;
EXAMPLE
%MACRO VELOCITY(SOURCE=,DATSET=,V1=,VARIABLE=,Z1=);
DATA &DATSET;
SET &SOURCE;
&VARIABLE=&V1 &Z1;
RUN;
%MEND;
%VELOCITY(DATSET=SPEED,SOURCE=RACE,V1=DISTANCE,Z1=TIME_MIN,VARIA
BLE=SPEED);
EXAMPLE
%MACRO IMPORTING(DATANAME=,PATH=,FORMAT=);
PROC IMPORT DATAFILE=&PATH
OUT=&DATANAME
DBMS=&FORMAT;
RUN;
%MEND;
DATA RACING;
INPUT RACER $ 5-14 BIKE $ 15-33 DISTANCE TIME_MIN;
DATALINES;
MIKE MV Agusta F3 326 15
ROGER Kawasaki 300 25
ELLON KTM RC250 312 19
JAMES Aprilia RSV4 RF 253 45
JACK CHI Ducati Panigale R 340 8
;
RUN;
DATA RACING1;
SET RACING;
CALL SYMPUT('MOTORS',BIKE);
RUN;
%PUT &MOTORS.;
DATA RACING2;
SET RACING;
CALL SYMPUT('MOTORS'||COMPRESS(_N_),BIKE);
RUN;
%PUT &MOTORS1;
%PUT &MOTORS2;
%PUT &MOTORS3;
%PUT &MOTORS4;
%PUT &MOTORS5;
%PUT &RACER1;
THE ABOVE MACRO HOLD ONLY FIRST OBSERVATION. TO MAKE IT HOLD ALL
THE OBSERVATIONS THE PROGRAM SHOULD BE CODED IN THE BELOW FORM.
PROC SQL;
SELECT RACER INTO:RACER1 SEPARATED BY ' ' FROM RACING;
QUIT;
%PUT &RACER1;
OPTIONS MERROR;
DATA RACE;
INPUT RACER $ 5-14 BIKE $ 15-33 DISTANCE TIME_MIN;
DATALINES;
MIKE MV Agusta F3 326 15
ROGER Kawasaki 300 25
ELLON KTM RC250 312 19
JAMES Aprilia RSV4 RF 253 45
JACK CHI Ducati Panigale R 340 8
;
RUN;
%MACRO SPEED(DATSET,SOURCE,V1,Z1,VARIABLE);
DATA &DATSET;
SET &SOURCE;
&VARIABLE=&V1 &Z1;
RUN;
%MEND;
%SPED(NEW,RACE,DISTANCE,TIME_MIN,SPEED);
LOG WINDOW 'WARNING: Apparent invocation of macro SPED not
resolved.' IS DISPLAYED.
OPTIONS NOMERROR;
%SPED(NEW,RACE,DISTANCE,TIME_MIN,SPEED);
LOG WINDOW NO WARNING ISSUED.
OPTIONS NOSERROR;
%MACRO SPEEDA1(DATSET,SOURCE,V1,Z1,VARIABLE);
DATA &DATSET;
SET &SOURE;
&VARIABLE=&V1 &Z1;
RUN;
%MEND;
%SPEEDA1(NEW,RACE,DISTANCE,TIME_MIN,SPEED);
NOMPRINT: DOES NOT DISPLAY THE SAS STATEMENTS THAT ARE GENERATED
BY MACRO EXECUTION.
OPTIONS NOMPRINT;
%MACRO SPEED_A1(DATSET,SOURCE,V1,Z1,VARIABLE);
DATA &DATSET;
SET &SOURCE;
&VARIABLE=&V1 &Z1;
RUN;
%MEND;
%SPEED_A1(NEW1,RACE,DISTANCE,TIME_MIN,SPEED);
%MACRO SPEED_A2(DATSET,SOURCE,V1,Z1,VARIABLE);
DATA &DATSET;
SET &SOURCE;
&VARIABLE=&V1 &Z1;
RUN;
%MEND;
%SPEED_A2(SETA,RACE,DISTANCE,TIME_MIN,SPEED);
%SPEED_A3(SETB,RACE,DISTANCE,TIME_MIN,SPEED);
%MACRO SPEED_A4(DATSET,SOURCE,V1,Z1,VARIABLE);
DATA &DATSET;
SET &SOURCE;
&VARIABLE=&V1 &Z1;
RUN;
%MEND;
%SPEED_A4(SETB,RACE,DISTANCE,TIME_MIN,SPEED);
MACRO FUCTIONS
DATA E_11;
INFILE DATALINES;
INPUT EMP_ID: $ DES $:10. JDATE RDATE;
INFORMAT JDATE DATE7. RDATE DDMMYY10.;
FORMAT JDATE DATE7. RDATE DDMMYY10.;
LABEL JDATE='JOINING DATE';
DATALINES;
103 BROKER 14MAY11 04 05 2018
102 BANKER 01MAY13 09 12 2020
101 BAKER 10NOV14 09 11 2019
105 DOCTOR 11JUN12 06 04 2013
104 ATTORNEY 10MAR10 06 04 2017
;
RUN;
OPTIONS MPRINT;
%MACRO CASE_CHANGE(CREAT,SOURCE,VARIABLE1,VARIABLE2);
DATA &CREAT;
SET &SOURCE;
&VARIABLE1=TRANSLATE(&VARIABLE2,"ZO","BT");
RUN;
%MEND;
%CASE_CHANGE(RR,E_11,LOWERCASE,DES);
%LET NAME=%SYSFUNC(TRANSLATE(ATTORNEY_BAR,"ZO","BT"));
%PUT &NAME;
%MACRO MATRIX;
%GLOBAL NAME DESINATION JUSTIFICATION;
%LET NAME=%SYSFUNC(COMPBL('THIS IS
SAS PROGRAM.'));
%LET
DESINATION=%SYSFUNC(TRANSLATE(ATTORNEY_BAR,"ZO","BT"));
%MEND;
%MATRIX;
%PUT &NAME;
%PUT &DESINATION;
%MACRO BLUESKY;
%GLOBAL SCANNED SUBSTRR LENGTH UPCASE LOWCASE;
%LET SCANNED=%SCAN(THIS IS A SAS PROGRAM.,4);
%LET SUBSTRR=%SUBSTR(THE PROGRAMMMER,5,4);
%LET LENGTH=%LENGTH(THIS IS A SAS PROGRAM.);
%LET UPCASE= %UPCASE(this is american history);
%LET LOWCASE=%LOWCASE(CINEMA ARE GOOD ENTERTAINMENTS);
%MEND;
%BLUESKY;
%PUT THE SCANNED WORD IS:&SCANNED;
%PUT THE EXTRACTED PART IS:&SUBSTRR;
%PUT THE LENGTH OF THE STRING IS:&LENGTH;
%PUT THE STRING IS CONVERTD FROM LOW TO UP:&UPCASE;
%PUT THE STRING IS CONVERTED FROM HIGH TO LOW:&LOWCASE;
data PROFILE;
infile datalines;
input Name $ Sex $ Subject $:15. Age Marks Height Weight;
datalines;
Ellen M mathematics 15 66 153 55
Sam M English 12 88 169 70
cristana F Social 14 56 165 60
Maria F Science 15 71 160 66
John M French 13 45 154 64
Victoria F Mathematics 11 57 159 71
Britney F Arabic 19 64 161 59
Abdul M English 13 47 162 54
Vikram M Social 17 47 144 72
Alisha F French 18 22 166 74
Alisha M French 18 22 166 74
Mona F Arabic 11 87 156 45
William M Science 16 55 161 77
Alisha F French 18 22 66 74
Alberta F English 14 61 162 71
;
run;
OPTION MLOGIC;
%MACRO CREATE (NEWDATA,OLDDATA);
DATA &NEWDATA;
SET &OLDDATA;
IF SEX='F' THEN COLOR='GREEN';
ELSE COLOR='RED';
RUN;
%MEND;
%CREATE(NDS,PROFILE);
DATA DENGUE;
INFILE DATALINES;
INPUT NAME $ 5-11 TEMPERATURE PLATELETS_LAKHS DEATH $;
DATALINES;
JENSON 105 0.54 Y
NEEL 104 0.36 Y
RAMSON 105 0.41 Y
ELLEN 104 0.42 N
;
RUN;
%MACRO REPORT(D_SET,SOURCE);
DATA &D_SET;
SET &SOURCE;
IF DEATH='Y' THEN OUTPUT;
RUN;
%MEND;
%REPORT(NEW,DENGUE);
%MACRO REP(D_SET,RESOURCE);
DATA &D_SET;
SET &RESOURCE;
IF DEATH='Y' THEN DO;
AGE='OLDER';
BP='HIGH';
OUTPUT;
END;
RUN;
%MEND;
%REP(NEW2,DENGUE);
SQL
(STRUCTURED QUERY LANGUAGE)
QUERY ORDER
MEMORIZING THE ORDER
SELECT SOME
FROM FRENCH
WHERE WAITER
GROUP BY GROW
HAVING HEALTHY
ORDERY BY ORANGES
PROC SQL;
CREATE TABLE JOB(ID NUM, DESIGNATION CHAR(10), JOINING
CHAR(10), SALARY NUM);
QUIT;
PROC SQL;
INSERT INTO JOB
SET ID=104, DESIGNATION='DOCTOR', JOINING='16SEP2014',
SALARY=152361
SET ID=105, DESIGNATION='LAWYER', JOINING='10MAR2018',
SALARY=12000;
QUIT;
ASSIGNING LABELS
PROC SQL;
CREATE TABLE EMP(ID NUM 'IDENTIFICATION NUMBER', NAME
CHAR(15) 'NAME OF THE EMPLOYEE', DOJ NUM
FORMAT=DATE9.'DATE OF JOINING');
INSERT INTO EMP
VALUES(101, 'SAMUEL','09NOV2015'D)
VALUES(102,'JOHN','10DEC2010'D)
VALUES(103, 'SMITH','15JAN2009'D);
QUIT;
DATA STANDARD;
INFILE DATALINES;
INPUT NAME $ SEX $ SUBJECT $:15. AGE MARKS HEIGHT WEIGHT;
DATALINES;
ELLEN M MATHEMATICS 15 66 153 55
SAM M ENGLISH 12 88 169 70
CRISTANA F SOCIAL 14 56 165 60
MARIA F SCIENCE 15 71 160 66
JOHN M FRENCH 13 45 154 64
VICTORIA F MATHEMATICS 11 57 159 71
BRITNEY F ARABIC 19 64 161 59
ABDUL M ENGLISH 13 47 162 54
VIKRAM M SOCIAL 17 47 144 72
ALISHA F FRENCH 18 22 166 74
MONA F ARABIC 11 87 156 45
WILLIAM M SCIENCE 16 55 161 77
ALBERTA F ENGLISH 14 61 162 71
;
RUN;
ORDER BY OPTION:IT SORTS THE VARIABLE IN THE ORDER AS SPECIFIED
PROC SQL;
SELECT FROM STANDARD ORDER BY AGE;
QUIT;
PROC SQL;
SELECT FROM STANDARD ORDER BY AGE DESC;
QUIT;
DESC: THIS IS USED FOR SORTING IN DESCENDING ORDER
ASC: THIS IS USED FOR SORTING IN ASCENDING ORDER
PROC SQL;
SELECT FROM STANDARD ORDER BY AGE DESC, MARKS ASC;
QUIT;
WHERE QUERY IS USED FOR SELECTION
PROC SQL;
SELECT FROM STANDARD WHERE AGE <=16 ORDER BY MARKS DESC,
AGE ASC;
QUIT;
PROC SQL;
SELECT FROM STANDARD WHERE SEX='M';
QUIT;
PROC SQL;
SELECT FROM STANDARD WHERE SEX='M' AND AGE=13;
QUIT;
PROC SQL;
SELECT FROM STANDARD WHERE AGE BETWEEN 13 AND 17;
QUIT;
PROC SQL;
SELECT , CASE WHEN AGE=11 THEN MARKS+2
WHEN AGE=12 THEN MARKS+1.5
WHEN AGE=13 THEN MARKS+1
WHEN AGE=14 THEN MARKS+5
WHEN AGE=15 THEN MARKS+2.5
WHEN AGE=16 THEN MARKS-3
WHEN AGE=17 THEN MARKS-1.5
WHEN AGE=18 THEN MARKS+6.5
ELSE MARKS+10 END AS NEW_MARKS FROM
STANDARD;
QUIT;
PROC SQL;
SELECT , CASE WHEN AGE >=11 AND AGE<13 THEN "A+"
WHEN AGE>=13 AND AGE<15 THEN 'B+'
WHEN AGE>=15 AND AGE<17 THEN 'A++'
WHEN AGE>=17 AND AGE<18 THEN 'B---'
ELSE 'B+++' END AS RATING FROM STANDARD;
QUIT;
MULTIPLE CASE WHEN STATEMENTS
PROC SQL;
SELECT , CASE WHEN AGE=11 THEN MARKS+2
WHEN AGE=12 THEN MARKS+1.5
WHEN AGE=13 THEN MARKS+1
WHEN AGE=14 THEN MARKS+5
WHEN AGE=15 THEN MARKS+2.5
WHEN AGE=16 THEN MARKS-3
WHEN AGE=17 THEN MARKS-1.5
WHEN AGE=18 THEN MARKS+6.5
ELSE MARKS+10 END AS NEW_MARKS,
CASE WHEN AGE >=11 AND AGE<13 THEN "A+"
WHEN AGE>=13 AND AGE<15 THEN 'B+'
WHEN AGE>=15 AND AGE<17 THEN 'A++'
WHEN AGE>=17 AND AGE<18 THEN 'B---'
ELSE 'B+++' END AS RATING FROM STANDARD;
QUIT;
PROC SQL;
UPDATE STANDARD SET MARKS=
CASE WHEN AGE>11 AND AGE<13 THEN MARKS-25
WHEN AGE>=13 AND AGE<15 THEN MARKS-15
WHEN AGE>=15 AND AGE<19 THEN MARKS+13
ELSE MARKS+12 END;
QUIT;
QUIT;
DATA TREAT;
INPUT PID $ 5-15 TREATED $;
DATALINES;
APOLLO-104 PARACET
APOLLO-105 DICLOF
APOLLO-106 LOSART
APOLLO-106 LEVOCET
;
RUN;
DATA TREATMENT;
INPUT PID $ 5-15 TREATED $;
DATALINES;
APOLLO-101 PARACET
APOLLO-102 DICLOF
APOLLO-103 LOSART
APOLLO-104 PARACET
;
RUN;
DATA STANDARD;
INFILE DATALINES;
INPUT NAME $ SEX $ SUBJECT $:15. AGE MARKS HEIGHT WEIGHT;
DATALINES;
ELLEN M MATHEMATICS 15 66 153 55
SAM M ENGLISH 12 88 169 70
CRISTANA F SOCIAL 14 56 165 60
MARIA F SCIENCE 15 71 160 66
JOHN M FRENCH 13 45 154 64
VICTORIA F MATHEMATICS 11 57 159 71
BRITNEY F ARABIC 19 64 161 59
ABDUL M ENGLISH 13 47 162 54
VIKRAM M SOCIAL 17 47 144 72
ALISHA F FRENCH 18 22 166 74
MONA F ARABIC 11 87 156 45
WILLIAM M SCIENCE 16 55 161 77
ALBERTA F ENGLISH 14 61 162 71
;
RUN;
MODIFICATION OF TABLES:
1. ADDING VARIABLES.
2. DROP THE VARIABLE
3. ASSIGN CONTSRAINTS
4. CREATE COSTRAINTS.
DATA TORNADO;
INFILE DATALINES;
INPUT STATE $&14. MILES_PER_HOUR $ SPEED_OF_SOUND_MACH ;
DATALINES;
ALABAMA 80 2
CALIFORNIA 56 3
CONNECTICUT 91 1
DELAWARE 74 5
FLORIDA 71 2
IOWA 42 2
MARYLAND 87 5
MASSACHUSETTS 15 1
NEVADA 36 8
TENNESSEE 75 2
TEXAS 58 6
WISCONSIN 74 2
WYOMING 80 2
;
RUN;
DATA TORNADO1;
SET TORNADO;
RUN;
PROC SQL;
ALTER TABLE TORNADO1 ADD LIGHTENING CHAR(20);
QUIT;
PROC SQL;
UPDATE TORNADO1 SET LIGHTENING = CASE WHEN
SPEED_OF_SOUND_MACH<=3 THEN 'NOT OCCURED' ELSE 'OCCURED' END ;
QUIT;
DATA TORNADO2;
SET TORNADO1;
RUN;
PROC SQL;
ALTER TABLE TORNADO2 DROP LIGHTENING;
QUIT;
PROC SQL;
DELETE FROM TORNADO2 WHERE SPEED_OF_SOUND_MACH<=3;
QUIT;
DATA TORNADO3;
SET TORNADO1;
RUN;
PROC SQL;
DROP TABLE TORNADO3;
QUIT;
DATA SPORTS6;
INPUT TEAM $ NAME $ SCORE $;
DATALINES;
US SAM A+
US JOHN B-
US PELO A
UK JEM O
UK MOUZ C
CA BEN A+
UK BEZA A
;
RUN;
DATA SPORTS7;
INPUT TEAM $ NAME $ SCORE $;
DATALINES;
NZ RAZ C-
NZ MAZ A-
NZ REN C+
US PELO A
CA BEN A+
CA LEE B+
CA BEN A+
;
RUN;
PROC SQL;
SELECT FROM SPORTS6 WHERE NAME IN (SELECT NAME FROM
SPORTS7);
QUIT;
PROC SQL;
SELECT FROM SPORTS6 WHERE NAME NOT IN(SELECT NAME FROM
SPORTS7);
QUIT;
UNIONS
DATA SPORTS;
INPUT TEAM $ NAME $ SCORE $;
DATALINES;
US SAM A+
US JOHN B-
US PELO A
UK JEM O
UK MOUZ C
UK BEZA A
;
RUN;
DATA SPORTS1;
INPUT TEAM $ NAME $ SCORE $;
DATALINES;
NZ RAZ C-
NZ MAZ A-
NZ REN C+
CA BEN A+
CA LEE B+
CA BEN A+
;
RUN;
DATA SPORTS2;
INPUT TEAM $ NAME $ SCORE $;
DATALINES;
US SAM A+
US JOHN B-
US PELO A
UK JEM O
UK MOUZ C
UK BEZA A
;
RUN;
DATA SPORTS3;
INPUT TEAM $ NAME $ SCORE $;
DATALINES;
NZ RAZ C-
NZ MAZ A-
NZ REN C+
US PELO A
CA BEN A+
CA LEE B+
CA BEN A+
;
RUN;
PROC SQL;
CREATE TABLE INTER AS SELECT FROM SPORTS2
INTERSECT
SELECT FROM SPORTS3;
QUIT;
PROC SQL;
CREATE TABLE INTER1 AS SELECT , 'PLAYERS FROM COUNTRIES' AS
COUNTRIES_FROM FROM SPORTS2
INTERSECT
SELECT , 'PLAYERS FROM
COUNTRIES' AS CCOUNTRIES_FROM FROM SPORTS3;
QUIT;
DATA SPORTS4;
INPUT TEAM $ NAME $ SCORE $;
DATALINES;
US SAM A+
US JOHN B-
US PELO A
UK JEM O
UK MOUZ C
CA BEN A+
UK BEZA A
;
RUN;
DATA SPORTS5;
INPUT TEAM $ NAME $ SCORE $;
DATALINES;
NZ RAZ C-
NZ MAZ A-
NZ REN C+
US PELO A
CA BEN A+
CA LEE B+
CA BEN A+
;
RUN;
PROC SQL;
CREATE TABLE INTER2 AS SELECT TEAM,NAME FROM SPORTS4
EXCEPT
SELECT TEAM, NAME FROM SPORTS5;
QUIT;
JOINS
TYPES OF JOINS:
1.SIMPLE JOIN
2.INNER JOIN
3.LEFT JOIN
4.RIGHT JOIN
5.CROSS JOIN
6.FULL JOIN
DATA MFG;
INPUT @5MFG $9. MODEL $ PRICE;
DATALINES;
BENZ B-CLASS 10000
BMW X6 15213
SUZUKI WINZ 12457
HONDA ACCORD 14567
TATA JAGUAR 19856
;
RUN;
DATA CARS;
INPUT @5MFG $9. MODEL $ MILEAGE_MPS $;
DATALINES;
MAHENDRA XUV 15
BENZ B-CLASS 12
BMW X6 15
SUZUKI WINZ 16
ISUZ MUX 14
;
RUN;
SIMPE JOIN
PROC SQL;
CREATE TABLE SIMP AS SELECT FROM MFG,CARS WHERE
MFG.MFG=CARS.MFG;
QUIT;
INNER JOIN
PROC SQL;
CREATE TABLE INN1 AS SELECT FROM MFG INNER JOIN CARS ON
MFG.MFG=CARS.MFG;
QUIT;
PROC SQL;
CREATE TABLE INN2 AS SELECT FROM MFG INNER JOIN CARS ON
MFG.MFG=CARS.MFG AND MFG.MODEL=CARS.MODEL;
QUIT;
LEFT JOIN
PROC SQL;
CREATE TABLE LEF AS SELECT FROM CARS LEFT JOIN MFG ON
CARS.MFG=MFG.MFG;
QUIT;
PROC SQL;
CREATE TABLE RIG1 AS SELECT FROM MFG RIGHT JOIN CARS ON
MFG.MFG=CARS.MFG;
QUIT;
SO IN THE ABOVE RIGHT JOIN WE ARE NOT GETTING THE ALL COMMON
VARIABLES. TO OVERCOME THIS BELOW
FORM OF TABLE SHOULD BE WRITTEN.
FULL JOIN
PROC SQL;
CREATE TABLE FUL AS SELECT COALESCE(MFG.MFG,CARS.MFG) AS
MFG,COALESCE(MFG.MODEL,CARS.MODEL) AS MODEL, PRICE,
MILEAGE_MPS FROM MFG FULL JOIN CARS ON MFG.MFG=CARS.MFG;
RUN;
CROSS JOIN: THIS JOIN PRODUCES CARTESIAN PRODUCT. CARESIAN
PRODUCT IS NOTHING BUT ONE OBSERVATION COMBINES
WITH ALL THE OBSERVATIONS WITH THE OTHER DATASET
PROC SQL;
CREATE TABLE CROSS AS SELECT FROM CARS CROSS JOIN MFG;
QUIT;
FUNCTIONS
DATA ATHLETICS;
INFILE DATALINES;
INPUT @5PLAYER $10. RACE1_MPS RACE2_MPS RACE3_MPS RACE4_MPS
RACE5_MPS;
DATALINES;
AKBAR 45 48 43 49 51.9
ANTONY 51 36 49.2 41 59
SAMUEL 46 56 41 42.3 49
ELLON 49 . 63 67 43
. 63 12 32 41 14
;
RUN;
PROC SQL;
SELECT DISTINCT(RACE5_MPS) AS DISTINCT_OBSERVATION FROM
ATHLETICS1;
QUIT;
ONLINE CLASS WILL BE PROVIDED FOR THE BELOW SAS PROGRAMMING TOPICS. COST
OF THE COURSE IS $436.
1. DATA STATEMENT
2. INFILE STATEMENT
3. INPUT STATEMENT
4. FORMAT AND INFORMAT
5. CONDITIONAL STATEMENTS
6. ITERATIVE DO LOOPS
7. DM STATEMENT
8. COMBINING DATASETS
9. FUNCTIONS
10. OPTIONS
11. ARRAYS
12. IMPORTING AND EXPORTING THE DATA
13. PROC CONTENTS
14. PROC COMPARE
15. PROC TRANSPOSE
16. PROC MEANS
17. PROC FREQUENCY
18. PROC RANK
19. PROC SGPLOT
20. PROC CORR
21. PROC REG
22. PROC ANOVA
23. PROC PRINT
24. PROC REPORT
25. MACROS
26. SQL
27. ODS
ONLINE CLASS WILL BE PROVIDED FOR THE CLINICAL SAS PROGRAMMER. COST OF THE
COURSE IS $750.
1. DATA STATEMENT
2. INFILE STATEMENT
3. INPUT STATEMENT
4. FORMAT AND INFORMAT
5. CONDITIONAL STATEMENTS
6. ITERATIVE DO LOOPS
7. DM STATEMENT
8. COMBINING DATASETS
9. FUNCTIONS
10. OPTIONS
11. ARRAYS
12. IMPORTING AND EXPORTING THE DATA
13. PROC CONTENTS
14. PROC COMPARE
15. PROC TRANSPOSE
16. PROC MEANS
17. PROC FREQUENCY
18. PROC RANK
19. PROC SGPLOT
20. PROC CORR
21. PROC REG
22. PROC ANOVA
23. PROC PRINT
24. PROC REPORT
25. MACROS
26. SQL
27. ODS
28. INTRODUCTION TO CLINICAL TRIAL
29. SDTM DOMAINS
a. INTRODUCTION TO STDM
b. DOMAIN
i. DEMOGRAPHICS(DM)
ii. CONCOMITANT MEDICATION(CM)
iii. EXPOSURE(EX)
iv. SUBSTANCE USE(SU)
v. ADVERSE EVENTS(AE)
vi. MEDICAL HISTORY(MH)
vii. DISPOSITION
viii. ECG TEST RESULTS(EG)
ix. LABORATORY TEST RESULTS(LB)
c. Supplementary domain
d. validation