You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
data_null_;
dsid=open('outpath.test');
check=varnum(dsid,'col_name');
if check=0thenput'Variable does not exist';
elseput'Variable is located in column ' check +(_1) '.';
run;
query schema table
/*find the nvar and nobs*/proc sql;
select nvar, nobs
fromdictionary.tableswhere libname='mylibname'and memname in ('dataset1','dataset2');
quit;
Summary stat
* Note that n is number of non-missing values;proc means data=dev nnmissminmeanmedianmax;
weight weight1;
var&varlist;
outputout=dev_profile;
run;
Remove missing values
dataCompleteCases;
setA;
ifnmiss(of _NUMERIC_)=0; /* output complete cases for all numeric vars; nmiss converts char to num. */run;
dataCompleteCases;
setSashelp.Heart;
if cmiss(of _ALL_)=0; /* complete cases for all vars; cmiss doesn't convert char/num; */run;
Manipulation Data
Keep appending rows to a dataset
/*create an initial empty dataset; note that this create an extra artificial column; TODO:this might be a better way */dataoutlib.rv;
run;
%do%until(...);
/*generate a tmp dataset with the extra rows*/dataoutlib.rv;
setoutlib.rvtmp;
run;
dataoutlib.rv;
setoutlib.rv;
if_n_=1thendelete; /*remove the empty row*/run;
%end;
split dataset according to data type
proc contents data=inlib.indata out=outlib.contout;
run;
dataoutlib.out1outlib.out2;
setoutlib.contout;
iftype=1thenoutput outlib.out1; /*type=1 is numerics which includes date and time*/iftype=2thenoutput outlib.out2; /*type=2 is char*/run;
write some data to file
data_null_;
file"&path/output.sas"mod;
setindataend=eof;
if_n_=1then"%"'let var_list=';
putvar;
if eod thenput";";
DATA_NULL_;
SETindata(where=(name ne"&name."and val ne"&val."));
CALLSYMPUT('VAR'||LEFT(PUT(_N_,4.)),name); /*think of key-value pair: VARi=name where name is the value of the variable name in current row*/CALLSYMPUT('NVARS',_N_); /*this count the total*/RUN;
/*this is how to use the list of macro variables*/%DOI=1%TO%EVAL(&NVARS);
DATAtmp;
lengthvarname $32;
set &prefix..&&VAR&I; /*&&VAR&I is replaced by the value of VARi* /run;data outdata; set outdata tmp; run; %end;