Learning SAS by example: A Programmers Guide

Problem 7.10 #3

Using the Sales data set, list the observations for employee numbers (EmpID) 9888 and 0177. Do this two ways, one using OR operators and the other using IN Operator.

The code I currently have written but its generating an error:

*______*
[Question 7.10 #3]
[Cindy Herrera]
[Description: create a temporary data ]
[called voter in order to use in the next ]
[problem.];
filename Sales '/home/cherrera0/my_courses/sue.mcdaniel/Wks 5_6/Sales.xls'; /*naming the file sales to the ! program */
PROC IMPORT DATAFILE=SALES /* Importing the Sales file */
DBMS=XLS /* Determining what type of file is being used */
OUT=WORK.IMPORT;
GETNAMES=YES; /* Using the Xls names as file type */
run;
title "Selected Employees from Sales";
proc print data=learn.sales;
where EmpID = '9888' or EmpID = '0177';
run;
proc print data=learn.sales;
where EmpID in ('9888' '0177');
run;

Problem 7.10 #4

Using the Sales data set, create a new, temporary SAS data set containing Region and TotalSales plus new variable called Weight with values of 1.5 for the North Region. 1.7 for the South Region, and 2.0 for the West and East Regions. Use a SELECT statement to do this.

The code I currently have written but its generating an error:

*______*
[Question 7.10 #4]
[Cindy Herrera]
[Description: create a temporary data ]
[called voter in order to use in the next ]
[problem.];
filename Sales '/home/cherrera0/my_courses/sue.mcdaniel/Wks 5_6/Sales.xls';
PROC IMPORT DATAFILE=SALES /* Importing the Sales file */
DBMS=XLS /* Determining what type of file is being used */
OUT=WORK.IMPORT;
GETNAMES=YES; /* Using the Xls names as file type */
run;
data sales;
set learn.sales (keep=Region TotalSales);
select (Region);
when (Region = 'North') weight =1.5; *making new weight variable;
when (Region = 'South') weight =1.7;
when (Region = 'West','East') weight =2.0;
otherwise;
end;
run;

Problem 7.10 #6

Using the Sales data set, list all the observation where Region is North and Quantity is less than 60. Include in this list any observations where the customer name (Customer) is Pet’s are Us.

The code I currently have written but its generating an error, but there is an output of the table:

*______*
[Question 7.10 #6]
[Cindy Herrera]
[Description: create a temporary data ]
[called voter in order to use in the next ]
[problem.];
filename Sales '/home/cherrera0/my_courses/sue.mcdaniel/Wks 5_6/Sales.xls'; /*naming the file sales to the ! program */
PROC IMPORT DATAFILE=SALES /* Importing the Sales file */
DBMS=XLS /* Determining what type of file is being used */
OUT=WORK.IMPORT;
GETNAMES=YES; /* Using the Xls names as file type */
run;
data learn.regions;
set learn.regions(keep = Region Quantity customer);
select;
where (Region eq "North" and Quantity is 60 and Quantity is not missing) or
Customer = "Pet's are Us";
end;
run;
title "Listing of Customers";
proc print data=learn.regions noobs;
run;

Problem 8.9 #4

Count the number of missing values for the variables A, B, and C in the Missing data set. Add the cumulative number of missing values to each observation (use variable names MissA, MissB, and MissC). Use the MISSING function to test for the missing values.

The code I currently have written but its generating an error

filename missing '/home/cherrera0/my_courses/sue.mcdaniel/Wks 5_6/missing.txt'; /*naming the file sales to the ! program */
PROC IMPORT DATAFILE=SALES /* Importing the Sales file */
DBMS=XLS /* Determining what type of file is being used */
OUT=WORK.IMPORT;
GETNAMES=YES; /* Using the Xls names as file type */
data learn.missing;
infile '/home/cherrera0/my_courses/sue.mcdaniel/Wks 5_6/missing.txt';
set learn.missing;
input MissAMissBMissC;
if missing(MissA) then misscounterMissA + 1;
if missing(MissB) then misscounterMissB + 1;
if missing(MissC) then misscounterMissC + 1;
run;
title "Listing of Missing";
proc print data=missing;
run;

Problem 8.9 #14

Generate a table of integers and square starting at 1 and ending when the square value is greater than 100. Use either a DO UNTIL or DO WHILE statement to accomplish this.

The code I currently have written but its generating an error (lost on how to do this…)

data square;
infile '/home/cherrera0/my_courses/sue.mcdaniel/Wks 5_6/missing.txt';
do n = 1 to 1000 until (n**2 ge 100);
NSquare = n**2;
output;
end;
run;
title "Listing of SQUARE";
proc print data=square;
run;