The examples in this documentation reference default SAS libraries (Sashelp) or describe the management of temporary and permanent data, but do not provide SAS code examples directly in this segment. Code examples for data creation or table usage will be extracted from related sections if available.
1 Code Block
DATA STEP Data
Explanation : This example illustrates the creation and use of a temporary table 'MyTempTable' in the Work library. By specifying only the name 'MyTempTable' without a libref, SAS stores it in Work by default. This table will be automatically deleted at the end of the SAS session.
Copied!
/* Ce code crée une table temporaire 'MyTempTable' dans la bibliothèque Work. */
DATA MyTempTable;
input ID Name $;
datalines;
1 John
2 Jane
;
RUN;
PROC PRINT DATA=MyTempTable;
RUN;
1
/* Ce code crée une table temporaire 'MyTempTable' dans la bibliothèque Work. */
2
DATA MyTempTable;
3
INPUT ID Name $;
4
DATALINES;
5
1 John
6
2 Jane
7
;
8
RUN;
9
10
PROC PRINTDATA=MyTempTable;
11
RUN;
2 Code Block
LIBNAME Data
Explanation : This code block shows how to assign a 'User' library to a specified file path, designating it as the default library for permanent storage of files created with a single-level name. 'MyPermanentTable' is thus saved permanently. It also demonstrates how to force the use of the Work library for temporary data by using a two-level name (Work.AnotherTempTable) even if 'User' is active.
Copied!
/* Assigne la bibliothèque User à un dossier pour le stockage permanent. */
LIBNAME User '/sas/data/user_lib'; /* Remplacez par votre chemin réel */
/* Crée une table permanente 'MyPermanentTable' dans la bibliothèque User. */
DATA MyPermanentTable;
input Product $ Quantity;
datalines;
Apple 100
Orange 150
Banana 200
;
RUN;
PROC PRINT DATA=MyPermanentTable;
RUN;
/* Si la bibliothèque User est assignée, SAS cherchera 'MyPermanentTable' ici. */
/* Pour créer une table temporaire explicitement dans Work, utilisez un nom à deux niveaux. */
DATA Work.AnotherTempTable;
input Item $ Price;
datalines;
Pen 1.50
Paper 3.00
;
RUN;
PROC PRINT DATA=Work.AnotherTempTable;
RUN;
1
/* Assigne la bibliothèque User à un dossier pour le stockage permanent. */
2
LIBNAME User '/sas/data/user_lib'; /* Remplacez par votre chemin réel */
3
4
/* Crée une table permanente 'MyPermanentTable' dans la bibliothèque User. */
5
DATA MyPermanentTable;
6
INPUT Product $ Quantity;
7
DATALINES;
8
Apple 100
9
Orange 150
10
Banana 200
11
;
12
RUN;
13
14
PROC PRINTDATA=MyPermanentTable;
15
RUN;
16
17
/* Si la bibliothèque User est assignée, SAS cherchera 'MyPermanentTable' ici. */
18
/* Pour créer une table temporaire explicitement dans Work, utilisez un nom à deux niveaux. */
19
DATA Work.AnotherTempTable;
20
INPUT Item $ Price;
21
DATALINES;
22
Pen 1.50
23
Paper 3.00
24
;
25
RUN;
26
27
PROC PRINTDATA=Work.AnotherTempTable;
28
RUN;
3 Code Block
PROC CONTENTS / PROC PRINT
Explanation : This example uses 'PROC CONTENTS' to display the tables and catalogs available in the Sashelp library. 'PROC PRINT' is then used to view a data sample from the 'Class' table in the Sashelp library, demonstrating access to data provided by SAS for documentation and examples.
Copied!
/* Liste le contenu de la bibliothèque Sashelp. */
PROC CONTENTS DATA=Sashelp._ALL_ NODS;
RUN;
/* Affiche les 5 premières lignes de la table 'CLASS' de Sashelp. */
PROC PRINT DATA=Sashelp.Class(OBS=5);
RUN;
1
/* Liste le contenu de la bibliothèque Sashelp. */
2
PROC CONTENTSDATA=Sashelp._ALL_ NODS;
3
RUN;
4
5
/* Affiche les 5 premières lignes de la table 'CLASS' de Sashelp. */
6
PROC PRINTDATA=Sashelp.Class(OBS=5);
7
RUN;
4 Code Block
PROC CATALOG
Explanation : This example uses 'PROC CATALOG' to examine the contents of the Sasuser.Profile catalog. This catalog stores user settings and customizations, such as environment preferences or function key definitions. It shows the items stored in the Sasuser library for the current user.
Copied!
/* Liste le contenu du catalogue Sasuser.Profile. */
PROC CATALOG CATALOG=Sasuser.Profile ENTRYTYPE=ALL;
CONTENTS;
RUN;
1
/* Liste le contenu du catalogue Sasuser.Profile. */
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.
« Understanding default libraries is fundamental to managing your session’s data lifecycle. SAS uses a two-level naming convention (libref.filename). If you omit the first level (e.g., DATA MyTable;), SAS defaults to a specific storage location based on your environment configuration. Mastery of these defaults ensures you don't accidentally lose data or clutter shared resources. »
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.