Showing posts with label sas dataset. Show all posts
Showing posts with label sas dataset. Show all posts

Commonly Asked SAS Interview Questions with Answer : 16 -20

Ques 16 : Could you write a data step to create a SAS dataset with minimum use of SAS rules and letters?

Ans :      Data ;          
                 X=1;       
                 Run;



Ques 17 : Why have you not written SAS dataset name in above answer ? Would it get run or not ?

Ans :  The above example would get run as if we don't provide the sas dataset name in data step then SAS would use its by default sas dataset names that are 'DATA1, DATA2........DATAn.



Ques 18 : What would happen if I write "DATE" in place of Data in answer 16 ? It's just a typo mistake. Would it get run or not ? 'Yes' / 'No'... Explain.

Ans : It would get run with a warning like 'Assuming the symbol DATA was misspelled as DATE'.

for more info : Types of ERRORs in SAS



Ques 19 : What is _NULL_ and why have you not used this for question 16 ? What about the _LAST_ ?

Ans : You have asked to create a SAS dataset in above question and of course minimum letters of English.

_NULL_ is the default keyword in SAS which execute a datastep but does not create any dataset so i have not used it.

_LAST_ defines the most recently created SAS dataset. If we execute any Data step or Proc step without specifying any input dataset then by default SAS uses the _LAST_.



Ques 20 : Where we can use SAS datasets name ? How ? When ? Why ?

Ans : We named SAS dataset name when we need to create them.
If we want to create an output dataset in data step then we need to provide it in DATA Statement.

If we want to create an output dataset in Proc step then we need to name it in Procedure or in Output Statement.

If we don't provide any data set name then SAS would use it's default dataset names.

We can use SAS dataset name with following Statements, Procedures, Function and Options:

A.  Data Statement
B.  Set Statement
C.  Merge Statement
D.  Update Statement
E.  Modify Statement
F.  Data = DSN ( as option of any SAS procedure )
G. Open function

Whenever we create sas view, we also name SAS dataset name in SAS Procedure ( in PROC SQL ) and View = Option for Data step.





* Today I played both the role ( Interviewer and Candidate ), If you feel that answers are not completely polite in nature. I just tried to show some attitude in nature. Candidate is there to get the job not to beg the job. Attitude matters, it shows your confidence,But be POLITE.

Difference Between SAS SUM Function And Using '+' Operator In SAS

Hi All,

Operators :   For any type of calculation, we all are much familiar with Division (/), Multiplication (*), Addition (+) and Substraction (-) which are known as operators. Whenever we are in need to do some calculation in SAS, we use operators. Operators are to do indicated operation between SAS variables or constant values.

Sum Function in SAS :- It returns the sum of non missing and missing arguments.

Ex:          Total = Sum (U,M,A);

Total =  Sum (of  U1 - U10) ;

Total = Sum ( U M A );

"+" Operator in SAS :- It returns a missing value if any of the values (arguments ) are missing.

Difference between SAS Procedure and SAS function

  •  SAS functions would be in need for argument values to be supplied across an observation in SAS dataset.

  •  SAS functions are already written ( pre-written) expressions which gives programming shortcuts for many manipulation and calculation of data

  •  SAS functions are for normal (common ) mathematical operations such as square root, natural log and many more....

  •  SAS Procedures would be in need for one argument value per observation in SAS dataset.

Finding Max Observation By Data Step Only In SAS

Hi All,

Suppose we have a data set like below:

EmpID      EmpSal     EmpName

E001          5000          A

E002          7500          B

E003          2500          C

E004          9800          D

E005          6100          E

 

I am looking for the maximum salaried EmpID / EmpName or whatever which should contain maximum value from a variable.

then you can try like it, without using any procedures and options:

 

data want;

   set have nobs=_nobs_;

   if EmpSal > max_EmpSal then do;

     max_EmpSal = EmpSal;

     max_EmpID = EmpID;

     max_EmpName = EmpName;

   end;

   retain max_:;

   keep max_:;

   if _n_ = _nobs_;

run;