Question: 3 . Using an Iterative and Conditional DO Loop in SAS ( My answers are in the SAS coding below, which I want to confirm
Using an Iterative and Conditional DO Loop in SAS My answers are in the SAS coding below, which I want to confirm are correct or input to help correct my answers, thank you!
The pgeusports table contains European Union trade amounts for sport products. Belgium wants to see their exports exceed their imports for golf and racket products. They expect to annually increase exports by and want to achieve their goal within years.
a Open ppsas from the practices folder. Run the program and review the results. Notice that the golf export number is farther from the golf import number as compared to the racket export and import numbers.
b Add a conditional DO loop around the assignment statement for AmtExport.
i Use a DO WHILE statement that executes while the export value is less than or equal to the import value.
ii Create a Year column that increments by a value of
iii. Create a row of output for each year.
data pgeusports;
set pgeusports;
Year ;
do while AmtExport AmtImport;
output;
AmtExport AmtExport ;
Year ;
end;
run;
c Run the program and review the results.
Partial Results of Rows
d How many years did it take until the exports exceeded the imports, and what is the final Year value for each sport product?
proc sql;
select SportProduct, maxYear as FinalYear, count as NumberofYears
from pgeusports
group by SportProduct;
quit;
SportProduct Number of Years Final Year
GOLF
RACKET
e Modify the DO statement to include an iterative portion before the conditional portion. The iterative portion needs to be based on Year values of to years
data pgeusports;
set pgeusports;
do Year to ;
do while AmtExport AmtImport;
output;
AmtExport AmtExport ;
end;
end;
run;
f Within the DO loop, delete any statements related to the incrementing of Year.
g Run the program and review the results. The results show data rows.
h Complete this table based on your last modification:
proc sql;
select SportProduct, maxYear as FinalYear, count as NumberofYears,
case when AmtExport AmtImport then 'Yes' else No end as DoExportsexceedImports
from pgeusports
group by SportProduct;
quit;
SportProduct Number of Years Final Year Do Exports exceed Imports?
GOLF
RACKET
i Delete the OUTPUT statement.
j Run the program and review the results.
k Do these Year values equal the final Year values before deleting the OUTPUT statement? Why or why not?
lOptional Include a conditional OUTPUT statement within the DO loop that will show the two rows of output with the Year values equal to the final Year values before deleting the OUTPUT statement.
data pgeusports;
set pgeusports;
do Year to ;
do while AmtExport AmtImport;
if Year then output;
AmtExport AmtExport ;
end;
end;
run;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
