Published on :
Macro SASHELP

Exercise: Dynamic Creation of Macro Variables with PROC SQL

This code is also available in: Deutsch Español English Français
This script is an exercise template for learning. The objective is to use PROC SQL to extract student names from the SASHELP.CLASS table and store them in a single macro variable (&STUDENT_LIST), separated by spaces. It also requires retrieving the total number of records via the automatic SQLOBS variable.
Data Analysis

Type : SASHELP


Data comes from the standard SASHELP.CLASS example table.

1 Code Block
PROC SQL
Explanation :
Main exercise block where the student must add the 'into :STUDENT_LIST separated by " "' clause and assign the value of &SQLOBS to &NUM_STUDENTS.
Copied!
1PROC SQL noprint;
2 select /* Add required SQL syntax here */
3 from sashelp.class;
4 /* Add %LET statement here */
5QUIT;
2 Code Block
MACRO STATEMENT
Explanation :
Displaying results in the SAS log for exercise validation.
Copied!
1options nosource;
2%put ======================;
3%put Number of Students: &NUM_STUDENTS;
4%put Student List: &STUDENT_LIST;
5%put ======================;
6options SOURCE;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : Instructor : Josh Horstman