0% found this document useful (0 votes)
41 views9 pages

Sas Asst 3

The document discusses various SAS concepts and functions including: 1. The SET statement is used to read data from existing SAS datasets in libraries, while the INPUT statement defines variables and reads data values. 2. The WORK library is the default library in SAS and is temporary, while SASHELP and SASUSER are permanent libraries. 3. Character and numeric data types are the basic building blocks in SAS. Character variables can hold letters, numbers, and special characters, while numeric variables hold only numbers. 4. Common character functions in SAS include UPCASE, LOWCASE, PROPCASE, LENGTH, SUBSTR, SCAN and CAT which can manipulate and extract parts of character strings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views9 pages

Sas Asst 3

The document discusses various SAS concepts and functions including: 1. The SET statement is used to read data from existing SAS datasets in libraries, while the INPUT statement defines variables and reads data values. 2. The WORK library is the default library in SAS and is temporary, while SASHELP and SASUSER are permanent libraries. 3. Character and numeric data types are the basic building blocks in SAS. Character variables can hold letters, numbers, and special characters, while numeric variables hold only numbers. 4. Common character functions in SAS include UPCASE, LOWCASE, PROPCASE, LENGTH, SUBSTR, SCAN and CAT which can manipulate and extract parts of character strings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

1.

Which statement is used for extracting existing dataset from SAS


library? Give example?
Ans ;- SET statement is used for existing dataset from SAS library.
Examples are
DATA L;
SET SASHELP.CLASS;
RUN;
2. Wr ite the syntax to create library in SAS?
ANS;- 1. LENGTH MUST BE 8 CHARCTERS
2. STARTS WITH ALPHABET OR UNDERSCORE & FOLLWED BY
NUMBEWRS.
GENERAL SYNTAX TO CREATE LIBRARIES;-
LIBNAME LIBREF “EXTERNAL FOLDER PATH”
LIBNAME ABC”C:\USERS\HP\DESKTOP\NEWFOLDER(5)”;
DATA PQR.K;
DATA ABC.K;
INPUT NAMES$;
CARDS;
JKL
;
RUN;
3. Which is the default library in SAS?
A. SAS HELP (PERMANENT)…….>SAS SUPPORTING FILES AND
DATASETS.
B. SAS USER (PERMANENT)…….>SAS SUPPORTING FILES AND DATA
SETS.
C. WORK (TEMPORARY)……..>DEFAULT STORE
4. What are the two building blocks in SAS?
ANS;- A. CHARACTER DATATYPE
B. NUMERIC DATA TYPE
CHARACTER DATATYPE NUMERIC DATA TYPE
i) A-Z i) 0-9
ii) a-z ii) +,-,X,/,*
iii) MINIMUM& MAXIMUM MEMORY iii) MINIMUM&MAXIMUM MEMORY
1 – 32767 BYTES 3-8BYTES
iv) Default memories iv) Default memories
8 bytes 8 bytes.
v) Missing values blank ( ) v) missing values period .
5. What is the default memory for data types?
ANS;- 8 bytes
6. What is the minimum and maximum memory for Character
data type?
ANS;- 1- 32767 BYTES
7. What is the minimum and maximum memory for Numeric data
type?
ANS;- 3-8 BYTES
8. What is INFILE?
The INFILE statement will define the data source, while the INPUT statement will
codify the format and move the data into SAS.
INFILE……..>TO EXTRACT SOURCE FILE/DELIMITED FILE INTO SAS
ENVIRONMENT
9. WHAT is Input?
TO CREATE / DEFINE THE VARIABLES.
10.What is Cards?
CARDS…….> IT IS SYNTAX WHERE THE CODE WILL START.
11.What are the rules for creating dataset?
GENERAL SYNTAX TO CREATE DATA SETS
DATA DSN 1 DSN2 …….;(DSN……>DATA SET NAME)
INPUT VAR1 VAR2………;(INPUT…….> TO CREATE / DEFINE THE
VARIABLES)
12.How to extract delimited file into SAS environment?
INFILE…..>TO EXTRACT SOURCE FILE/DELIMITED FILE INTO SAS
ENVIRONMENT
DATA C;
INFILE "C:\Users\Welcome\Desktop\New Text Document.txt";
INPUT KMS PLACES$;
RUN;
13.Wr ite the dataset to create EID AND ENAME variables and assign
values to variables?
DATA A;
INPUT EID ENAME$;
CARDS;
12 SUMATHI
14 MAHESWARI
;
RUN;
14.What are the missing values for Char and Num datatype?
TO IDENTIFY DATA VALUE ERROR IN PARTICULAR ITERATION
IT HAS TWO VARIABLES
_ERROR_........>BOOLEAN VARIABLES
0.......>NO ERROR
1.......>ERROR (NO OF ITERATION)
_N_
NUMBER OF ITERATION.IT HAS TWO PHASES.
1. COMPLITION PHASE....> SYNTAX ERROR
2. EXECUTION PHASE.....>DATA VALUE ERROR

15.What is PDV?
PDV ......>PROGRAMME DATA VECTOR
TO IDENTIFY DATA VALUE ERROR IN PARTICULAR ITERATION
IT HAS TWO VARIABLES
_ERROR_........>BOOLEAN VARIABLES
0.......>NO ERROR
1.......>ERROR (NO OF ITERATION)
_N_
NUMBER OF ITERATION.IT HAS TWO PHASES.
3. COMPLITION PHASE....> SYNTAX ERROR
4. EXECUTION PHASE.....>DATA VALUE ERROR

DATA A;
INPUT ID EMPNAMES$;
CARDS;
101 ABC
102 DEF
;
RUN;
DATA A;
INPUT ID EMPNAMES;
CARDS;
101 ABC
102 DEF
;
RUN;
16.What are Libraries in SAS?
 SAS USER LIBRARY
 SAS HELP LIBRARY
 WORK LIBRARY
 MAPS LIBRARY
 MAPSSAS LIBRARY
17.List the input styles? Give examples?
The INPUT statement reads raw data from in stream data lines or external
files into a SAS data set. You can use the following different input styles.
Depending on the layout of data values in the records: list input. Column
input. Formatted input.

18.What are Character Functions?


 UPCASE
 LOWCASE
 PROPCASE
 LENGTH
 COMPRESS
 COMPBL
 CAT
 RIGHT
 LEFT
 SUBSTR
 SCAN
 TRANSLATE
 TRANWRD
 INDEX
 INDEC
 INDEXW
19.In SASHELP.CLASS,convert NAME variable,all letters into upcase,
lowcase and propcase?
20.What is LENGTH funct ion? Give examp le?
LENGTH…..>IT WILL COUNT LENGTH OF STRING INCLUDING
BLANK.
DATA W;
K="CLINICAL SAS PROGRAMMING";
H="LENGTH(K);
RUN;

DATA EE;
SET SASHELP.CLASS;
Z=LENGTH(NAME);
RUN;
21.In SASUSER. EMPDATA,calculate the length of variable "Division"?
22.In SASHELP.CLASS,calculate the length of var iable "NAME"?
23.What is SUBSTRING Function and give syntax for Substring?
SUBSTRING (SUBSTR):- TO EXTRACT A PART OF CHARCTERFROM A
STRING
VARIABLE=SUBSTR(STRING,START POSITION, NO OF CHARCTERS)
DATA I;
R=”CLINICAL SAS PROGRAMMING”;
D=SUBSTR(R,1,7);
O=SUBSTR(R,2,5);
L=SUBSTR(R,3,6);
K=SUBSTR(R,10,3);
RUN;
24.What is SCAN Function and give syntax for Scan?
SCAN: - TO EXTRCT PART OF WORD
VARIABLE=SCAN (STRING NO OF WORD)
DATA I;
R=” CLINICAL SAS PROGRAMMING”;
G=SCAN(R,3);
RUN;
25.What is Compress and Compbl Function? Give example?
COMPRESS
A. REMOVES SPECIFIC CHARACTER FROM A STRING
B. REMOVES A BLANKS/SPACES IN A STRING.
DATA S;
O=”MY CITY IS BLR”;
D=”COMPRESS(O);
RUN;
COMPBL
MULTIPLE SPACES TO SINGLE SPACES REMOVAL
DATA T;
E="CLINICAL SAS PROGRAMMING";
D=COMPBL(E);
RUN;
26.In the SASHELP.CLASS Dataset, extract the first letter from the
variable "NAME"?
27.What is INDEX,INDEXC,INDEXW used for? Give examples?
INDEX……..> TO CHECK THE PATTERN STRING
DATA Y;
O=”THIS IS MY FULL OF CHOCOLATES”;
P=INDEX(O,”LA”);
RUN;
INDEXC….> IT PARTICULLARYCHECKS THE INDIVIDUAL CHARCTER
IN A STRING
DATA OO;
O=”THIS IS MY BOX IS FULL OF CHOCOLATES”;
P=INDEXC(O,”HTO”);
RUN;
INDEXW…….>DATA OO;
O=”THIS IS MY BOX IS FULL OF CHOCOLATES”;
D=INDEXW(O,”BOX”);
E=INDEXW(O,”box”);
RUN;
28.What is difference between CAT and CATX function? Give
example?
CAT....>JOINS CHARCTER EXPRESSION/STRINGS WITHOUT
REMOVING THE BLANKS/SPACES COMBINES THE STRINGS.
VAIABLE =CAT (STRING1,STRING2......>)
DATA D;
Q="CLINICALK";
R="SAS";
D="PROGRAMMING";
S=CAT(Q,R,D);
RUN;

CATX.......>COMBINES THE STRINGS AND INSERTS THE SEPARATOR


BETWEEN THE STRINGS.
VARIABLE=CATX (SEPARATOR”,STRING1,STRING2......>)

DATA CATX;
K="KARNATAKA";
M="MUMBAI";
C="CHENNAI";
X=CATX("@",K,M,C);
RUN;
29.Using SASUSER.EMPDATA, combine both first and last name and
the result should be stored in the variable Fullname?
30.Extract the second word for the fol lowing dataset
DATA SC1;
T=" KOLAR AND MULBAGAL";
RUN;
31.For the following data set,Find INDEX,INDEXC AND INDEXW DATA
11;
P="my name is MYine";
Q=index(P,"MY");
R=INDEXC(P,"My");
S=INDEXW(P,"is");
Run;
32.Data P3;
J="BANGALORE";
K="KERALA";
L="BLR";
RUN;
1. Combine the strings and result should be stored in Variable P
2. $ should get placed between the strings.
Data P3;
J="BANGALORE";
K="KERALA";
L="BLR";
M=CAT(J,K,L);
RUN;

Data P3;
J="BANGALORE";
K="KERALA";
L="BLR";
M=CAT(J,K,L);
RUN;
33. What is the difference between SUBSTR AND SCAN?
SUBSTRING (SUBSTR):- TO EXTRACT A PART OF CHARCTERFROM A
STRING
VARIABLE=SUBSTR(STRING,START POSITION, NO OF CHARCTERS)
DATA I;
R=”CLINICAL SAS PROGRAMMING”;
D=SUBSTR(R,1,7);
O=SUBSTR(R,2,5);
L=SUBSTR(R,3,6);
K=SUBSTR(R,10,3);
RUN;
SCAN: - TO EXTRCT PART OF WORD
VARIABLE=SCAN (STRING NO OF WORD)
DATA I;
R=” CLINICAL SAS PROGRAMMING”;
G=SCAN(R,3);
RUN;
34.Write the syntax to extract .csv file and text file?
INFILE……..>TO EXTRCT SOURCE FILE/DELIMINATED FILE TO SAS
ENVIRONMENT
35. What are lnfile Options?
The INFILE statement will define the data source, while the INPUT statement will codify the
format and move the data into SAS.
INFILE……..>TO EXTRACT SOURCE FILE/DELIMITED FILE INTO SAS
ENVIRONMENT

36. What is the difference between Missover and Truncover? give


examples?
MISSOVER Sets all empty vars to missing when reading a short line. However, it can also skip
values. STOPOVER Stops the DATA step when it reads a short line. TRUNCOVER Forces the
INPUT statement to stop reading when it gets to the end of a short line.

DATA F;
INFILE "C:\Users\Welcome\Desktop\MISSOVER.txt" MISSOVER;
INPUT DIS 1-3 LOC$ 5-13;
RUN;

PROC PRINT DATA=F;


RUN;

DATA G;
INFILE "C:\Users\Welcome\Desktop\TRUNOVER.txt" TRUNCOVER;
INPUT KMS 1-4 LOC$ 5-13;
RUN;

PROC PRINT DATA=F;


RUN;

37. What is DLMand DSD? Give examples?


DLM……..>DELIMTER

DSD………> DATA SENSITIVE DELIMITER


When you specify DSD , SAS treats two consecutive delimiters as a missing value and
removes quotation marks from character values. Whereas the default functionality of
DLM=',' is to treat consecutive commas as a single comma, DSD will assign missing
values between consecutive commas.
DATA C;
INFILE "C:\Users\Welcome\Desktop\DLM.txt" DLM="+,-,*";
INPUT NAME$ ID DIS;
RUN;

PROC PRINT DATA=C;


RUN;

DATA D;
INFILE "C:\Users\Welcome\Desktop\DSD.txt" DLM="-" DSD;
INPUT NAME$ PLACE$ ID;
RUN;

PROC PRINT DATA=D;


RUN;
Ob NAME I DIS
s D
1 A 2 100
2 B 4 100

Obs NAME PLACE ID


1 S-A-S TPT 1000
2 S-A-P BLR .
38. What are the rules to follow in DSD?
When you specify DSD , SAS treats two consecutive delimiters as a missing value and
removes quotation marks from character values. Whereas the default functionality of
DLM=',' is to treat consecutive commas as a single comma, DSD will assign missing
values between consecutive commas.
DATA D;
INFILE "C:\Users\Welcome\Desktop\DSD.txt" DLM="-" DSD;
INPUT NAME$ PLACE$ ID;
RUN;

PROC PRINT DATA=D;


RUN;

You might also like