lunes, 20 de marzo de 2017

Analizar código SAS desde R


Interesante entrada sobre como analizar código SAS desde R:

Librería sasmap



En el post se explica como analizar código SAS desde R, obteniendo los procedimientos utilizados, pasos data, llamadas a macro y obteniendo incluso un flujo del proceso con la librería sasmap de Mango Solutions.

.......................................................................................................................................................

Interesting post that explain how to analyze SAS code from SAS:

sasmap library


The sasmap library obtain information such as procs used, data steps, call to macros, also yo can obtain a workflow of the SAS code. sasmap is a library of Mango Solutions

martes, 7 de marzo de 2017

Examen ejemplo certificación SAS "Base Programmer" (II)

Continuando el post anterior ejemplo examen certificación SAS BASE, añadimoos otro ejemplo de examen del certificado: 'SAS Certified Base Programmer for SAS 9''





As a continuation of the previous post: Example exam of SAS BASE certification, we add another example of exam of the certification:  'SAS Certified Base Programmer for SAS 9''

Examen / Exam:

Question 1:

data test;
set sasuser.employees;
if 2 le years_service le 10 then
amount = 1000;
else if years_service gt 10 then
amount = 2000;
else
amount = 0;
amount_per_year = years_service / amount;
run;

Which one of the following values does the variable AMOUNT_PER_YEAR contain if an employee has been with the company for one year?
A. 0
B. 1000
C. 2000
D. . (missing numeric value)

Answer : D (missing). It returns missing value as amount will be 0.
SAS Log: NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to missing values.

Question 2:

The contents of the raw data file NAMENUM are listed below:
--------10-------20-------30
Joe xx

The following SAS program is submitted:
data test;
infile 'namenum';
input name $ number;
run;

Which one of the following is the value of the NUMBER variable?
A. xx
B. Joe
C. . (missing numeric value)
D. The value can not be determined as the program fails to execute due to errors.
Answer : C. It is because number is defined as a numeric variable so it is expecting a numeric value but it reads xx, so number will be a missing value.

Question 3:

How many of the following variable names will not produce errors in an assignment statement?

variable
var
1variable
var1
#var
_variable#

A. 0
B. 1
C. 3
D. 6

Answer : C ; variable var var1. A variable cannot start with numeric or special characters except _. You also cannot use special characters anywhere in the name either though numeric values are allowed.

Question4:

Suppose the variable 'Unit_Cost_Price' (numeric) contains both missing and non missing values. What would the following code return?

proc sort data=ecsql1.price_list;
 by Unit_Cost_Price;
run;

A. A new dataset work.price_list is created with Unit_Cost_Price sorted in ascending order with missing values at the bottom of the dataset
B. The dataset ecsql1.price_list is sorted with Unit_Cost_Price sorted in descending order with missing values at the bottom of the dataset
C. A new dataset work.price_list is created with Unit_Cost_Price sorted in descending order with missing values at the top of the dataset
D. The dataset ecsql1.price_list is sorted with Unit_Cost_Price sorted in ascending order with missing values at the top of the dataset

Answer : D. It is because missing values are considered as lowest values (ascending order; they will be top of the data set)

Question 5:

 The following SAS program is submitted:

   dta work.il_corn;
    set corn.state_data;
    if state = 'Illinois';
   run;
The keyword "data" is misspelled above. What happens to this program during the compilation phase assuming "corn" is a valid libref?


A. The program fails due to syntax errors
B. The DATA step compiles but doesn't execute
C. The DATA step compiles and executes 
D. None of the above

Answer : C. It compiles and executes as SAS assumed that the 'dta' was data. But it leaves a warning in log window.

Question 6

Which of the following is a valid statement about the VALUE range in the PROC FORMAT procedure? It cannot be...

A. A single character or numeric value
B. A range of character values
C. A list of unique values separated by commas
D. A combination of character and numeric values
Answer : D.

Question 7

The following SAS program is submitted:

libname sasdata 'SAS-data-library';
data test;
set sasdata.chemists (keep = job_code);
if job_code = 'chem3'
then description = 'Senior Chemist';
run;

The variable JOB_CODE is a character variable with a length of 6 bytes.

Which one of the following is the length of the variable DESCRIPTION in the output data set?
A. 6 bytes
B. 8 bytes
C. 14 bytes
D. 200 bytes

Answer : C. The length of 'Senior Chemist' is 14.

Question 8

The following SAS program is submitted:

data work.totalsales (keep = monthsales{12} );
set work.monthlysales (keep = year product sales);
array monthsales {12} ;
do i=1 to 12;
monthsales{i} = sales;
end;
run;

The data set named WORK.MONTHLYSALES has one observation per month for each of five years for a total of 60 observations.

Which one of the following is the result of the above program?
A. The program fails execution due to data errors.
B. The program fails execution due to syntax errors.
C. The program executes with warnings and creates the WORK.TOTALSALES data set.
D. The program executes without errors or warnings and creates the WORK.TOTALSALES data set.

Answer : B. The syntax issue lies in this line of code - keep = msales{12}
To correct the syntax issue, replace keep = msales{12} with keep = msales1-msales12


Question 9

The following SAS program is submitted:

data work.accounting;
set work.dept1 work.dept2;
run;

A character variable named JOBCODE exists in both the WORK.DEPT1 and WORK.DEPT2 SAS data sets. The variable JOBCODE has a length of 5 in the WORK.DEPT1 data set and a length of 7 in the WORK.DEPT2 data set. 

Which one of the following is the length of the variable JOBCODE in the output data set?

A. 5     
B. 7     
C. 8     
D. 12 

Answer : Since SAS checks the variable Job_code in DEPT1 for the first time of length of 5 Bytes. it sets the length to be 5. All the values that are read from DEPT2 are truncated to Chars.


Question 10

Which one of the following SAS statements renames two variables?

A. set work.dept1 work.dept2(rename = (jcode = jobcode) (sal = salary));
B. set work.dept1 work.dept2(rename = (jcode = jobcode sal = salary));
C. set work.dept1 work.dept2(rename = jcode = jobcode sal = salary);
D. set work.dept1 work.dept2(rename = (jcode jobcode) (sal salary));



Answer: B.  The syntax for RENAME is as follows :
RENAME=(old-name-1=new-name-1 old-name-2=new-name-2. . . old-name-n=new-name-n)



Formación SAS