EZ Study

Actuarial Biology Chemistry Economics Calculators Confucius Engineer
Physics
C.S.


SAS Interview Questions and Answers -5

*-------------------;
data one;
   x=0;
   y='01JUL2012'd;
   z='01JUL2012';
run;

** Describe the attributes of variables Y and Z in dataset one; 
** Y=Numeric, Z=Character;
** If you were to use variable X as a date value; 
**  what date would it be?

*-------------------;
data two;
   x='First Record'; output;
   x='Second Record'; output;
run;

** Explain any problems with the creation of dataset two;  
** X defaults to length 12, truncating 2nd observation at "Second Recor";


*-------------------;
data three;
   set two;
   rename x=y;
   label y = 'Employee Name';
run;

** Given dataset two has a variable x; 
**what issue exists in the above creation of dataset three;
** Labeling of Y variable is not allowed; 
**as Y will not actual exist until it is written to three;

*-------------------;
data four;
   set four;
   label x='Employee Name';
run;

proc datasets lib=work;
   modify four;
   label x='Employee Name';
run;

** Both of the above methods correctly label 
** variable X for pre-existing dataset four, 
**why would you use one ver the other.  
**The first method recreates dataset four entirely, 
**whereas the 2nd method just changes the descriptor header;


*-------------------;
data five1;
   x=1; name='bob'; output;
run;

data five2;
   x=1; name='sally'; output;
run;

data names;
   merge five1 five2;
      by x;
run;

** Within final dataset names, what will the value of name be;
** name=sal, due to overriding five1 value; 
** but picking up length $3 due to "bob" default assignment;


*-------------------;
data six1;
   i=2; name1='gusto'; output;
   i=2; name1='bobby'; output;
run;

data six2;
   i=2; name2='gus'; output;
   i=2; name2='bob'; output;
   i=1; name2='sam'; output;
   i=3; name2='sal'; output;
run;

data merge6;
   merge six1 (in=in1) six2 (in=in2);
      by i;
   if (in1) then name=name1;
   else name=name2;
run;

** Explain the above datastep for merging x and y together; 
** what problems exist if any;
** Dataset six2 is not in order of by variable I;
** Once sorted, problem exists in that more than 1 dataset 
** has multiple by variable I occurences;

 


     
   

Related links:

Continue SAS Interview Questions -1: Where vs. IF, Function   SAS Tutorial
Back SAS Interview Questions -4: Procedure vs. macro   SAS Interview