· Copy this program and paste it into the code editing window:
title;
proc sql;
select location,n(location) label='Count'
from sasuser.schedule,sasuser.register
where schedule.course_number=
register.course_number
group by location;
quit;
Submit the program and examine the output. The SELECT statement creates a listing from two SAS data sets (tables) that are merged (joined) by a common variable, Course_Number. The GROUP BY clause reduces the listing to distinct values of Location. The N function counts the number of observations that are within distinct values of the GROUP BY variable.
· Modify the program so that it creates and references these macro variables:
- table1 (the second-level name of one input data set)
- table2 (the second-level name of the other input data set)
- joinvar (the name of the variable that is in both input data sets)
- freqvar (the name of the GROUP BY variable).
Submit the program and compare the listing with the listing that was created earlier.
title;
%let table1=schedule;
%let table2=register;
%let joinvar=course_number;
%let freqvar=location;
proc sql;
select &freqvar,n(&freqvar) label='Count'
from sasuser.&table1,sasuser.&table2
where &table1..&joinvar= /* Here .. is necessary since the first is as delimiter to indicate the end of macro variable */
&table2..&joinvar
group by &freqvar;
quit;
No comments:
Post a Comment