SAS Sample Code

Create a tiny database method 1

data test;
do var1=1 to 10;
output;
end;

proc print data=test(obs=20);

Create a tiny database method 2

data test;
infile datalines;
* input varname [vartype];
input id2010 id2001 charid $5.;

* Add rows of data under datalines;
datalines;
1633900 1129771 one
78161 50892 two
14805 7785 three
;

proc print data=test(obs=10);
run;

Read in csv file method 1

data data.outfn;
infile “data/file.txt” missover lrecl=2000;

* The two numbers at the end of the line indicates the starting position and ending position of the var;
* For example, record_id can be read from postion 1 to position 12;
* $ indicates string variables;

input
RECORD_ID $ 1-12
UNITS_OF_SERVICE 34-40
run;

proc print data=data.outfn(obs=10);
run;

Read in xlsx file

%macro readxlsx(infn, sht, outfn);
PROC IMPORT OUT= &outfn
DATAFILE= “raw/&infn”
DBMS=XLSX REPLACE;
SHEET=”&sht”;
GETNAMES=YES;
RUN;

proc print data=&outfn(obs=10);
proc contents data=&outfn;
%mend;

Write out xlsx file

%macro writexlsx(infn, outfn);
PROC EXPORT DATA= &infn
OUTFILE= “raw/&outfn”
DBMS=XLSX REPLACE;
RUN;
%mend;

Write out html files

ods html body=”file.html”;

.. sas code ..

run;
ods html close;