Table of Contents
SAS Tutorials offer a comprehensive platform for learning and mastering the SAS software. To access data in SAS Tutorials, users can follow these steps:
1. Open the SAS software and navigate to the “Explorer” tab.
2. Under the “Explorer” tab, click on the “Libraries” option.
3. A new window will open, displaying all the available libraries.
4. Select the library that contains the desired data.
5. Once the library is selected, the data files will be displayed in the “Explorer” tab.
6. Users can then click on the desired data file to view its contents.
By following these steps, users can easily access and view data in SAS Tutorials, allowing for a more efficient and effective learning experience.
Viewing a Dataset Using the Viewtable Window
A SAS dataset can be viewed as a spreadsheet using the Viewtable window. To open a dataset in the Viewtable window:
- In the Explorer window, double-click on the Libraries icon to display the libraries that are available in the current session. If the dataset was created without being stored to a user-created library, it will be located in the “Work” library. Double-click on the icon of the library where the dataset is located.
- Locate the dataset icon and double-click on it. This will open your dataset as a spreadsheet.
A typical Viewtable view of a dataset looks like this:

Note that SAS is unable to execute any DATA or PROC steps on a dataset that is open in the Viewtable window. You will need to close your open Viewtable windows before you begin running your syntax.
Printing a Dataset to the Output Window with PROC PRINT
Alternatively, a SAS dataset can be viewed using the the PRINT procedure, which produces a print-out of your dataset in the Output window. The PRINT procedure offers the flexibility to specify what variables and/or observations to print. The general format of PROC PRINT is:
PROC PRINT DATA=dataset <options>;
BY variable(s);
ID variable;
VAR variable(s);
WHERE condition(s);
FORMAT formats;
RUN;In the first line of the SAS code above, PROC PRINT tells SAS to execute the print procedure on the dataset specified by the DATA= argument. Immediately following PROC PRINT is where you put any procedure-level options you want to include. Let’s review some of the more common options:
LABEL
Print variable labels instead of variable names if variable labels have been assigned. (Does not apply to value labels.)NOOBS
Do not print row numbers/row identifiers. (NOOBS is an abbreviation for “no observation numbers”.)
As with all SAS procedures, the DATA command is optional, but recommended. If you do not specify a dataset, SAS will use the most recently created dataset by default. Note that if you want to begin printing at a specific record number or print a range of records (such as the first 20 records), you can supply the FIRSTOBS and OBS options immediately after the name of the dataset passed to the DATA= argument, enclosed by parentheses. For example, the code
PROC PRINT DATA=sample (FIRSTOBS=20 OBS=30);
RUN;
will print all of the observations in the sample dataset from row 20 through row 30.
The other statements (BY, ID, VAR, WHERE, and FORMAT) are optional, but are useful when you want to change what content is printed:
- The
BYstatement is an optional statement that can be used to print the data in groups. Note that this action requires that the data is sorted with respect to the variable(s) included in theBYstatement. This can be achieved by running PROC SORT before running PROC PRINT. - The
IDstatement allows you to specify a variable containing unique identifier labels for each observation. The variable you specify in the ID statement will print as the observation identifier in place of a row number. - The
VARstatement allows you to specify which variables to print, and what order to print them in. If this statement is omitted, SAS will print all variables in the dataset. - The
WHEREstatement allows you to limit which rows are printed, based on a logical condition involving variables and values in your dataset. (If you want to print only the first n observations, or if you want to begin printing with the nth observation, use the FIRSTOBS and OBS options mentioned above.) We cover logical conditions in our Subsetting & Splitting Datasets tutorial. - The
FORMATstatement allows you to apply (or override) variable formats for printing. This can be useful, for example, if your numeric variables normally have 2-3 decimal places, but you to suppress decimal places in the PROC PRINT output. We cover variable formats and the FORMAT statement in our Informats and Formats tutorial.
There are other optional statements available in PROC PRINT; see the SAS Help and Documentation guide for their descriptions.
Example: printing observations by groups
Example. Using the sample dataset, let’s print the height and weight of each student (rounded to the nearest whole number), grouping them by gender, and use the students’ IDs in place of the observation numbers.
PROC SORT DATA=sample;
BY Gender;
RUN;
PROC PRINT DATA=sample LABEL;
BY Gender;
ID ids;
VAR Gender Height Weight;
FORMAT Height Weight 3.0;
RUN;Because we want to print observations by gender, we must first sort the data using PROC SORT. The BY statement specifies that we want to group the printed output by the levels of variable Gender. The ID statement specifies that variable StudentID should be printed instead of the observation number. Because we are only interested in the height and weight of each student, these two variables are specified in the VAR statement. (Note, however, that the variable given in the ID statement will automatically print, regardless of whether or not it is listed in the VAR statement.) Finally, a FORMAT statement specifies that height and weight should print with no decimal point. (Specifically, it says that the values should be no wider than three characters, and should have no decimal places.) This is what the beginning of the first page of output should look like:

The variables ids, Gender, Height, and Weight are displayed with respect to the categories of variable Gender. By default, the groups are listed in ascending order. (Recall that Male was coded as 0, and Female was coded as 1. SAS treats missing values as the smallest possible value, so students with missing values for Gender appear first, then Male students appear next, then Female students.)
[wpcc-iframe id=”feedbacksurvey” align=”middle” frameborder=”no” height=”800px” name=”qualtrics” scrolling=”auto” src=”https://kent.qualtrics.com/jfe/form/SV_1Fc8ye2G7gLEhb7″ title=”Tutorial Feedback Survey” width=”100%”]
Cite this article
stats writer (2024). How can I view data in SAS Tutorials?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-view-data-in-sas-tutorials/
stats writer. "How can I view data in SAS Tutorials?." PSYCHOLOGICAL SCALES, 24 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-i-view-data-in-sas-tutorials/.
stats writer. "How can I view data in SAS Tutorials?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-i-view-data-in-sas-tutorials/.
stats writer (2024) 'How can I view data in SAS Tutorials?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-view-data-in-sas-tutorials/.
[1] stats writer, "How can I view data in SAS Tutorials?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. How can I view data in SAS Tutorials?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
