Hauptseite >
Know How >
Business Intelligence >
SAS >
DATA Step
Allgemeines
Informationen über einen DataSet
Liste der Variablen eines Dataset
proc contents data=sashelp.class noprint out=work.metainfo;
run;
Ergibt dann die Ausgabe in das Dataset work.metainfo mit dne folgenden Inhalt:
Meta Data for SASHELP.CLASS
Obs NAME TYPE LENGTH VARNUM
1 Age 1 8 3
2 Height 1 8 4
3 Name 2 8 1
4 Sex 2 1 2
5 Weight 1 8 5
Anzahl Observations in einem DataSet: Variante 1
| In Makro Code
|
In Datastep Code
|
Mit PROC SQL
|
%let DSID=%sysfunc(open(<LIB>.<TAB>,in));
%let NOBS=%sysfunc(attrn(&DSID,nobs));
%if &DSID > 0 %then %let RC=%sysfunc(close(&DSID));
|
data _null_;
dsid = open(<LIB>.<TAB>);
nobs = attrn(dsid,'nobs');
rc = close(dsid);
put nobs=;
call symput( 'myMacVar' , trim( put( nobs,$8. ) );
run;
|
proc sql noprint;
select count(*) into :nobs
from <LIB>.<TAB>;
quit;
|
Anzahl Observations in einem DataSet: Variante 2
| Makro Code
|
Datastep Code
|
PROC SQL
|
|
data _null_;
if 0 then set test nobs=nobs;
call symputx(”nobs”,nobs);
stop;
run;
|
proc sql noprint;
select nobs into :nobs
from dictionary.tables
where libname='<LIB>' and memname=<TAB>'”;
quit;
|
Löschen von Data Sets
If you only want to delete the DATA files in the WORK data library, then try the following sample code:
PROC DATASETS LIB=work;
DELETE _ALL_ / MEMTYPE=DATA;
RUN;
If you want to delete everything in the WORK data library, including compiled macros, program catalogs, views, etc., then try the following sample code:
PROC DATASETS LIB=work KILL;
RUN;
Exportieren in eine Textdatei
| Makro Code
|
Datastep Code
|
|
filename out 'export.txt';
data _null_;
set a;
file out;
put var1 (var2-var10) ('09'x);
run;
|