Beruflich Dokumente
Kultur Dokumente
What SAS statements would you code to read an external raw data file to a
DATA step?
2. How do you read in the variables that you need?
3. Are you familiar with special input delimiters? How are they used?
4. If reading a variable length file with fixed input, how would you prevent SAS
from reading the next record if the last variable didn’t have a value?
5. What is the difference between an informat and a format? Name three informats
or formats.
6. Name and describe three SAS functions that you have used, if any?
7. How would you code the criteria to restrict the output to be produced?
8. What is the purpose of the trailing @? The @@? How would you use them?
9. Under what circumstances would you code a SELECT construct instead of IF
statements?
10. What statement do you code to tell SAS that it is to write to an external file? What
statement do you code to write the record to the file?
11. If reading an external file to produce an external file, what is the shortcut to write
that record without coding every single variable on the record?
12. If you’re not wanting any SAS output from a data step, how would you code the
data statement to prevent SAS from producing a set?
13. What is the one statement to set the criteria of data that can be coded in any step?
14. Have you ever linked SAS code? If so, describe the link and any required
statements used to either process the code or the step itself.
15. How would you include common or reuse code to be processed along with your
statements?
16. When looking for data contained in a character string of 150 bytes, which
function is the best to locate that data: scan, index, or indexc?
17. If you have a data set that contains 100 variables, but you need only five of those,
what is the code to force SAS to use only those variable?
18. Code a PROC SORT on a data set containing State, District and County as the
primary variables, along with several numeric variables.
19. How would you delete duplicate observations?
20. How would you delete observations with duplicate keys?
21. How would you code a merge that will keep only the observations that have
matches from both sets.
22. How would you code a merge that will write the matches of both to one data set,
the non-matches from the left-most data set to a second data set, and the non-
matches of the right-most data set to a third data set.
23. What is the Program Data Vector (PDV)? What are its functions?
24. Does SAS ‘Translate’ (compile) or does it ‘Interpret’? Explain.
25. At compile time when a SAS data set is read, what items are created?
26. Name statements that are recognized at compile time only?
27. Identify statements whose placement in the DATA step is critical.
28. Name statements that function at both compile and execution time.
29. Name statements that are execution only.
30. In the flow of DATA step processing, what is the first action in a typical DATA
Step?
31. What is _n_?
1. Ruksana Says:
April 17th, 2005 at 2:33 pm
hi there,
i am a student learning SAS. i need answer for SAS questions which are listed on
your site.
plz forward me the answers. thanks in advance.
Ruksana
2. srijana Says:
August 21st, 2006 at 12:13 am
13. What is the one statement to set the criteria of data that can be coded in any
step?
13. What is the one statement to set the criteria of data that can be coded in any
step?
Ans) SET
What SAS statements would you code to read an external raw data file to a
DATA step?
Ans:
Data XXX;
infile ‘yyy’;
input …..;
run;
If reading a variable length file with fixed input, how would you prevent SAS
from reading the next record if the last variable didn’t have a value?
Ans: Missover
What is the difference between an informat and a format? Name three informats
or formats.
Ans: informat to read the date. Format to write the data. Informats: comma.
dollar. date.
Formats can be same as informats
Name and describe three SAS functions that you have used, if any?
mean()
date()
today()
How would you code the criteria to restrict the output to be produced?
Ans: noprint
What is the purpose of the trailing @? The @@? How would you use them?
What statement do you code to tell SAS that it is to write to an external file? What
statement do you code to write the record to the file?
What is the one statement to set the criteria of data that can be coded in any step?
Ans: set
Have you ever linked SAS code? If so, describe the link and any required
statements used to either process the code or the step itself.
How would you include common or reuse code to be processed along with your
statements?
When looking for data contained in a character string of 150 bytes, which
function is the best to locate that data: scan, index, or indexc?
If you have a data set that contains 100 variables, but you need only five of those,
what is the code to force SAS to use only those variable?
Code a PROC SORT on a data set containing State, District and County as the
primary variables, along with several numeric variables.
How would you code a merge that will keep only the observations that have
matches from both sets.
Ans: data xxx
merge yyy(in = inxxx) zzz (in = inzzz)
by aaa;
if inxxx = 1 and inyyy = 1;
run;
How would you code a merge that will write the matches of both to one data set,
the non-matches from the left-most data set to a second data set, and the non-
matches of the right-most data set to a third data set.
What is the Program Data Vector (PDV)? What are its functions?
Ans: To store the current obs;
At compile time when a SAS data set is read, what items are created?
Ans: Descriptor portion of the data set, PDV.
In the flow of DATA step processing, what is the first action in a typical DATA
Step?
Ans: set the variables to missing.
What is _n_?
Ans: SAS variable to count the no of obs read.
5. Mohan Says:
November 22nd, 2006 at 11:12 am
If you have a data set that contains 100 variables, but you need only five of those,
what is the code to force SAS to use only those variable?
Code a PROC SORT on a data set containing State, District and County as the
primary variables, along with several numeric variables.
6. Mohan Says:
November 22nd, 2006 at 11:15 am
If you have a data set that contains 100 variables, but you need only five of those,
what is the code to force SAS to use only those variable?
Ans: Sorry, my apologies for the above answer for this question. The correct
answer is
use KEEP= option in the SET statement of the DATA step
7. thiyagarajan Says:
December 20th, 2006 at 8:38 am
Hi All,
13. What is the one statement to set the criteria of data that can be coded in any
step?
Ans:- Options
9. srinivas.MP Says:
January 2nd, 2007 at 10:07 am
2)I have 100 observations from that i want to create 5 datasets like
a1,a2,a3,a4,a5.Each data set should contain 20 observation each.For ex.a1 would
contain 1 to 20 obs and a2 would contain 21-40 like that…
data a1 a2 a3 a4 a5;
set ;
if obs>=1 and =21 and =41 and =61 and
hi
is the following code right for following question?
How would you code a merge that will write the matches of both to one data set,
the non-matches from the left-most data set to a second data set, and the non-
matches of the right-most data set to a third data set.
let us say x is the data set that had all the 199 observations…
data a1 a2 a3 a4 a5;
set x;
if firstobs=1 and obs=20 then proc print data =a1;
if firstobs=21 and obs=40 then proc print data =a2;
if firstobs=41 and obs=60 then proc print data =a3;
if firstobs=61 and obs=80 then proc print data =a4;
if firstobs=81 and obs=100 then proc print data =a5;
run;
if you do not want the output in log file you do not have to use proc print
At compile time when a SAS data set is read, what items are created?
1. input buffer
2. Program Data Vector (PDV)
3. Descriptor Information
When looking for data contained in a character string of 150 bytes, which
function is the best to locate that data: scan, index, or indexc?
can anyone please tell me if there is a sas user group or discussion forum near
fairfax, va
15. Kishore Kumar.Kandikatla Says:
March 25th, 2007 at 2:14 pm
13. What is the one statement to set the criteria of data that can be coded in any
step?
Ans:- Options
Answer:
data a1 a2 a3 a4 a5;
set x;
if _N_ >=1 and _N_ =21 and _N_ =41 and _N_ =61 and _N_ =81 and _N_
18. hi Says:
April 4th, 2007 at 1:04 am
data a1 a2 a3;
set x;
if _n_ >=1 and _n_ =21 and _n_ =41 and _n_
data a1 a2 a3 a4 a5;
set x;
select;
when (_n_ le 20) output a1;
when (20
At compile time when a SAS data set is read, what items are created?
While reading a SAS data set the input buffer will not be created. It will be
created only when the external data is read. So when a sas data set is read
How would you code a merge that will keep only the observations that have
matches from both sets.
Ans)
suppose their are two files difined. assume A & B,
Data infilea;
infile infilea;
input @1 id $char10.
@11 datafiled $char100.;
Proc Sort by id;
Data infileb;
infile infileb;
input @1 id $char10.
@11 datafiled $char100.;
Proc Sort by id;
Data_null_
Merger infilea(in=a) infileb (in=b) by id;
If A=B then
File Outfile;
Put @1 id Char10;
@11 Datafield $char100.
End;
How would you code a merge that will write the matches of both to one data set,
the non-matches from the left-most data set to a second data set, and the non-
matches of the right-most data set to a third data set.
I would like to estimate a Tobit model on panel data. PROC QLIM is supposed to
be the appropriate procedure. But did not find any details on how to tell PROC
QLIM that I am using panel data. Could you mind helping me please?
hi
%let A= 3
%let B= 4
%let C= &A + &B
%let C= &C
hi
%let A= 3
%let B= 4
%let C= &A + &B
%let C= &C
What is the value of %Put statement?
Please give me the answer.
c=3+4
Also firstobs and obs are dataset control options. Not execution time statements.
This code will never work.
let us say x is the data set that had all the 199 observations…
data a1 a2 a3 a4 a5;
set x;
if firstobs=1 and obs=20 then proc print data =a1;
if firstobs=21 and obs=40 then proc print data =a2;
if firstobs=41 and obs=60 then proc print data =a3;
if firstobs=61 and obs=80 then proc print data =a4;
if firstobs=81 and obs=100 then proc print data =a5;
run;
if you do not want the output in log file you do not have to use proc print
hi,
these is bharath,iam learning sas will anyone give me the answers for these
quetions .plz forward me
1.name statments that functions at both compile & execution time ?
2.name statments that are execution only ?
3.what is the difference between var A1-A4 &varA1–A4?
4.wat is the order of evaluation of the comparison operators : + - */** () ?
5.wat is the significance of the ‘OF’ in x= sum (OF a1-a4,a6,a9); ?
How would you code a merge that will write the matches of both to one data set,
the non-matches from the left-most data set to a second data set, and the non-
matches of the right-most data set to a third data set.
data a1 a2 ;
infile x;
if firstobs=1 and obs=20 then proc print data=a1;
if firstobs=21 and obs=40 then proc print data=a2;
run;
proc print data=a1 a2;
run;
Hi All,
Can anyone explain about:
Proc LIFETEST and Proc GLM
# How does SAS handle missing values in: assignment statements, functions, a
merge, an update, sort order, formats, PROCs?
# How many missing values are available? When might you use them?
# How do you test for missing values?
# How are numeric and character missing values represented internally?
When looking for contained in a character string of 150 bytes, which function is
the best to locate that data: scan, index, or indexc?
Ans: INDEX function. Scan just sub strings the data and INDEXC looks for one
char.
Which date function advances a date, time or date/time value by a given interval?
Ans: INTNX
In the following DATA step, what is needed for ‘fraction’ to print to the log? data
_null_; x=1/3; if x=.3333 then put ‘fraction’; run;
1.What SAS statements would you code to read an external raw data file to a
DATA step?
Answer: INFILE statement is used to read the external raw data fiel to a Data
Step.
3. Are you familiar with special input delimiters? How are they used?
Answer: Yes, Using INPUT statement and DLM=option and DSD optin to read
delimited file.
4. If reading a variable length file with fixed input, how would you prevent SAS
from reading the next record if the last variable didn’t have a value?
Answer: Using MISSOVER option in INFILE statement.
6. Name and describe three SAS functions that you have used, if any?
Answer: DAY(date) Today() SUBSTR(ARG,POSITION,N)SUM()
7. How would you code the criteria to restrict the output to be produced?
Answer: Using WHERE statement
8. What is the purpose of the trailing @? The @@? How would you use them?
Answer: Both are line hold specifiers, the difference is how long they hold a line
for input, The trailing@ is used to hold the line of the raw data for subsequent
INPUT statements, but releases that line when SAS returns to the top of DATA
step, the trailing @@ will hold the line even when SAS starts build a new
obsrvation.
10. What statement do you code to tell SAS that it is to write to an external file?
Answer: Using _null_ statement
11. What statement do you code to write the record to the file?
Answer: Using FILE and PUT statements
12. If reading an external file to produce an external file, what is the shortcut to
write that record without coding every single variable on the record?
Answer: Using EXPORT procedure
13. If you’re not wanting any SAS output from a data step, how would you code
the data statement to prevent SAS from producing a set?
Answer: _NULL_
14. What is the one statement to set the criteria of data that can be coded in any
step?
Answer: Where statement
15. Have you ever linked SAS code? If so, describe the link and any required
statements used to either process the code or the step itself.
16. How would you include common or reuse code to be processed along with
your statements?
MICRO
1)What SAS statements would you code to read an external raw data file to a
DATA step?
ans)infile statement
3)Are you familiar with special input delimiters? How are they used?
ans)yes . dlm=’,'; or dlm=’ ‘;etc
4)If reading a variable length file with fixed input, how would you prevent SAS
from reading the next record if the last variable didn’t have a value?
ans)use specific length or format
like input num 9. char $5.;
5)What is the difference between an informat and a format? Name three informats
or formats.
ans)informat is used to print the data from the dataset by ommitng some values
whereas format reads a data differntly then what is actually stored in the dataset
by adding our own values.
date, ddmmyy and worddate
6)Name and describe three SAS functions that you have used, if any?
ans)a=sum(a,b,c);
s=log(a);
d=lag(a);
7)How would you code the criteria to restrict the output to be produced?
ans) use format
8)What is the purpose of the trailing @? The @@? How would you use them?
ans)@ is coulmn pointer to get the specific value while @@ is used if variables
are less and value are more and u want to read each value
10)What statement do you code to tell SAS that it is to write to an external file?
ans)ods or datafile
12)If reading an external file to produce an external file, what is the shortcut to
write that record without coding every single variable on the record?
ans)dde and ods
13)If you’re not wanting any SAS output from a data step, how would you code
the data statement to prevent SAS from producing a set?
ans) data _null_;
14)What is the one statement to set the criteria of data that can be coded in any
step?
ans)set
15)Have you ever linked SAS code? If so, describe the link and any required
statements used to either process the code or the step itself.
ans)use macro
16)How would you include common or reuse code to be processed along with
your statements?
ans)using format
17)When looking for data contained in a character string of 150 bytes, which
function is the best to locate that data: scan, index, or indexc?
ans)scan
18)If you have a data set that contains 100 variables, but you need only five of
those, what is the code to force SAS to use only those variable?
ans)in input statement use only those variables name which u want.
19)Code a PROC SORT on a data set containing State, District and County as the
primary variables, along with several numeric variables.
ans)proc sort data=q;
by state;
run;
similarly other statements
21)How would you code a merge that will keep only the observations that have
matches from both sets.
ans)usning merge and dupkey
22)How would you code a merge that will write the matches of both to one data
set, the non-matches from the left-most data set to a second data set, and the non-
matches of the right-most data set to a third data set.
ans)merge , dupkey and nodupkey
23)What is the Program Data Vector (PDV)? What are its functions?
ans)memory that sas creates while running the sas program in compilation stage is
called PDV,
25)At compile time when a SAS data set is read, what items are created?
ans)variables
26)Name statements that are recognized at compile time only?
ans)data
30)In the flow of DATA step processing, what is the first action in a typical
DATA Step?
ans)creating the name of dataset.
31)What is _n_?
ans)new line
I have mentioned the correct answer for some Q. David and Ajay has already
mentioned the correct answer for the other Qs.
4)If reading a variable length file with fixed input, how would you prevent SAS
from reading the next record if the last variable didn’t have a value?
Use MISSOVER while the file is read
INFILE datalines MISSOVER;
5)What is the difference between an informat and a format? Name three informats
or formats.
Format is used to print the output in the desired format
e.g., date9. comma9. DDMMYY10.
Informat is used with the input file which helps to read the data in the desired
format to use it inside the program for valuation
INFORMATs can be used with the INPUT() function, and FORMAT with the
PUT() function.
8)What is the purpose of the trailing @? The @@? How would you use them?
SAS provides two line-hold specifiers.
The trailing at sign (@) holds the input record for the execution of the next
INPUT statement.
The double trailing at sign (@@) holds the input record for the execution of the
next INPUT statement, even across iterations of the DATA step.
input Name $20. @; or input Name $20. @@;
10)What statement do you code to tell SAS that it is to write to an external file?
Using FILE statement we can write the data from the external file. INFILE for
reading the data from the external file
18)If you have a data set that contains 100 variables, but you need only five of
those, what is the code to force SAS to use only those variable?
List Input
19)Code a PROC SORT on a data set containing State, District and County as the
primary variables, along with several numeric variables.
proc sort data=q;
by state District County;
run;
31)What is _n_?
No of times the data step executed