Examples use generated data (datalines) for CAS demonstrations, but other examples depend on external files not created in the code (marked external_data_not_found: 1).
1 Code Block
DATA STEP
Explanation : This example shows how to read raw data from an external file using the INFILE and INPUT statements. INFILE is required because the source data comes from an external text file.
Copied!
data weight;
infile <fileref> or <path-to-file;
input PatientID $ Week1 Week8 Week16;
loss=Week1-Week16;
run;
1
DATA weight;
2
INFILE or
3
INPUT PatientID $ Week1 Week8 Week16;
4
loss=Week1-Week16;
5
RUN;
2 Code Block
DATA STEP
Explanation : Specifies the file containing the input data directly using its physical name in quotes.
Explanation : Identifies the file to which the PUT statement writes data. This example shows writing conditions based on a 'loss' variable.
Copied!
file 'output-file';
data status;
if loss ge 5 and loss le 9 then
put idno loss 'AWARD STATUS=3';
else if loss ge 10 and loss le 14 then
put idno loss 'AWARD STATUS=2';
else if loss ge 15 then
put idno loss 'AWARD STATUS=1';
run;
1
file 'output-file';
2
DATASTATUS;
3
IF loss ge 5 and loss le 9THEN
4
put idno loss 'AWARD STATUS=3';
5
ELSEIF loss ge 10 and loss le 14THEN
6
put idno loss 'AWARD STATUS=2';
7
ELSEIF loss ge 15THEN
8
put idno loss 'AWARD STATUS=1';
9
RUN;
4 Code Block
%INCLUDE statement
Explanation : Allows you to incorporate statements or raw data from another file into your SAS job and execute them.
Copied!
%include 'source-file';
1
%include 'source-file';
5 Code Block
DATA STEP / FILENAME statement
Explanation : Assigns a fileref 'mydata' to an input file, then uses this fileref in the INFILE statement to read the data.
Explanation : Assigns a fileref 'mypgm' to a file containing program statements.
Copied!
filename mypgm 'source-file';
1
filename mypgm 'source-file';
10 Code Block
FILENAME statement
Explanation : Assigns a fileref 'myprinter' to an output device specified by its type and host options.
Copied!
filename myprinter <device-type>
<host-options>;
1
filename myprinter
2
;
3
11 Code Block
DATA STEP
Explanation : Uses the fileref 'mydata' (previously assigned) in the INFILE statement to read the data.
Copied!
data weight;
infile mydata;
input idno $ week1 week16;
loss=week1-week16;
1
DATA weight;
2
INFILE mydata;
3
INPUT idno $ week1 week16;
4
loss=week1-week16;
12 Code Block
DATA STEP
Explanation : Uses the fileref 'myreport' (previously assigned) in the FILE statement to conditionally write data.
Copied!
file myreport;
if loss ge 5 and loss le 9 then
put idno loss 'AWARD STATUS=3';
else if loss ge 10 and loss le 14 then
put idno loss 'AWARD STATUS=2';
else if loss ge 15 then
put idno loss 'AWARD STATUS=1';
run;
1
file myreport;
2
IF loss ge 5 and loss le 9THEN
3
put idno loss 'AWARD STATUS=3';
4
ELSEIF loss ge 10 and loss le 14THEN
5
put idno loss 'AWARD STATUS=2';
6
ELSEIF loss ge 15THEN
7
put idno loss 'AWARD STATUS=1';
8
RUN;
13 Code Block
%INCLUDE statement
Explanation : Includes the content of the file referenced by 'mypgm' in the SAS job.
Copied!
%include mypgm;
1
%include mypgm;
14 Code Block
FILENAME statement
Explanation : Assigns a fileref 'mydir' to a directory or PDS (Partitioned Data Set), allowing efficient access to multiple files.
Copied!
filename mydir 'directory-or-PDS-name';
1
filename mydir 'directory-or-PDS-name';
15 Code Block
DATA STEP
Explanation : Reads data from the file 'qrt1.data' located in the aggregate location referenced by 'mydir'.
Explanation : Conditionally writes data to the file 'awards' located in the aggregate location referenced by 'mydir'.
Copied!
file mydir(awards);
if loss ge 5 then put idno loss
'AWARD STATUS=3';
else if loss ge 10
then put idno loss 'AWARD STATUS=2';
else if loss ge 15
then put idno loss 'AWARD STATUS=1';
run;
1
file mydir(awards);
2
IF loss ge 5THEN put idno loss
3
'AWARD STATUS=3';
4
ELSEIF loss ge 10
5
THEN put idno loss 'AWARD STATUS=2';
6
ELSEIF loss ge 15
7
THEN put idno loss 'AWARD STATUS=1';
8
RUN;
17 Code Block
%INCLUDE statement
Explanation : Includes the content of the 'whole.program' file located in the aggregate location referenced by 'mydir'.
Copied!
%include mydir(whole.program);
1
%include mydir(whole.program);
18 Code Block
DATA STEP
Explanation : Reads column-wise binary data from a specified file, using INFILE options RECFM=F and LRECL=160.
Copied!
data out;
infile file-specification or path-to-file recfm=f lrecl=160;
input var1;
run;
1
DATA out;
2
INFILE file-specification or path-to-file recfm=f lrecl=160;
3
INPUT var1;
4
RUN;
19 Code Block
DATA STEP / PROC CASUTIL Data
Explanation : This example first prepares data in a SAS WORK library, then uses PROC CASUTIL to load this data onto the CAS server. This standard method does not allow direct application of DVR optimization during loading.
Copied!
/* Préparation des données dans WORK */
data maTableWork;
input PatientID $ Week1 Week8 Week16;
datalines;
P1 100 95 90
P2 80 78 75
P3 120 115 110
;
run;
/* Méthode standard - ne permet pas l'optimisation DVR directe */
proc casutil;
load data=maTableWork casout="maTableCAS";
quit;
1
/* Préparation des données dans WORK */
2
DATA maTableWork;
3
INPUT PatientID $ Week1 Week8 Week16;
4
DATALINES;
5
P1 1009590
6
P2 807875
7
P3 120115110
8
;
9
RUN;
10
11
/* Méthode standard - ne permet pas l'optimisation DVR directe */
12
PROC CASUTIL;
13
load DATA=maTableWork casout="maTableCAS";
14
QUIT;
20 Code Block
DATA STEP / PROC CAS Data
Explanation : This example first creates a temporary SAS table ('somedata') with repeated values. It then uses the PROC CAS UPLOAD statement to load this table onto the CAS server, directly applying the DVR format and VARCHAR conversion options. This optimizes memory usage in a single step. A preliminary cleanup and verification step is included.
Copied!
/* Création d'une table temporaire SAS pour l'exemple */
data somedata;
length id $8 name $20 value 8;
do id = 1 to 10;
name = cats('Item', id);
value = mod(id, 3) * 100;
output;
end;
/* Ajout de valeurs répétées pour montrer l'efficacité de DVR */
do id = 11 to 20;
name = 'Repeated';
value = 50;
output;
end;
run;
proc cas;
/* Nettoyage préalable si nécessaire */
action table.droptable / name="somedata" caslib="casuser" quiet=true;
/* Chargement optimisé */
upload /
/* Récupération dynamique du chemin physique de la table SAS */
path="%sysfunc(pathname(work))/somedata.sas7bdat"
/* Configuration de la table de sortie CAS */
casout={
caslib="casuser"
name="somedata"
promote=true, /* Rendre la table globale */
memoryformat="DVR", /* Activation de la compression DVR */
replication=0 /* Ajuster la réplication selon les besoins */
}
/* Options d'importation supplémentaires */
importoptions={
filetype="BASESAS",
varcharConversion=17 /* Convertit les CHAR > 16 octets en VARCHAR */
}
;
quit;
/* Vérification du format de la table en CAS (optionnel) */
proc casutil;
list tables caslib="casuser" level="memory";
quit;
1
/* Création d'une table temporaire SAS pour l'exemple */
2
DATA somedata;
3
LENGTH id $8 name $20 value 8;
4
DO id = 1 to 10;
5
name = cats('Item', id);
6
value = mod(id, 3) * 100;
7
OUTPUT;
8
END;
9
/* Ajout de valeurs répétées pour montrer l'efficacité de DVR */
/* Récupération dynamique du chemin physique de la table SAS */
24
path="%sysfunc(pathname(work))/somedata.sas7bdat"
25
26
/* Configuration de la table de sortie CAS */
27
casout={
28
caslib="casuser"
29
name="somedata"
30
promote=true, /* Rendre la table globale */
31
memoryformat="DVR", /* Activation de la compression DVR */
32
replication=0 /* Ajuster la réplication selon les besoins */
33
}
34
35
/* Options d'importation supplémentaires */
36
importoptions={
37
filetype="BASESAS",
38
varcharConversion=17/* Convertit les CHAR > 16 octets en VARCHAR */
39
}
40
;
41
QUIT;
42
43
/* Vérification du format de la table en CAS (optionnel) */
44
PROC CASUTIL;
45
list tables caslib="casuser" level="memory";
46
QUIT;
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.
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.