-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhead()
More file actions
105 lines (94 loc) · 3.12 KB
/
head()
File metadata and controls
105 lines (94 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
%macro head(data,obsnumber=5,includefirstobs=yes,linesize=132);
%if %sysfunc(exist(&data)) = 0 %then %do; %put ERROR: Data does not exist; %goto exit; %end;
%if &linesize > 256 %then %do; %put ERROR: Linesize must be between 64-256; %goto exit; %end;
%if &linesize < 64 %then %do; %put ERROR: Linesize must be between 64-256; %goto exit; %end;
%let alotequal = ;
%do i=1 %to &linesize;
%let alotequal = &alotequal=;
%end;
options LINESIZE=&linesize;
data temp; set &data(obs=&obsnumber); run;
proc contents data=temp out=Contents short noprint; run;
proc sort data=contents; by varnum; run;
proc sql noprint;
select name into :var1 -
from contents;
select type into :type1 -
from contents;
select count(*) into :noobs trimmed
from contents;
select count(*) into :number trimmed
from temp;
%do i=1 %to &noobs;
select &&var&i. into :temp&i._1 -
from temp;
%end;
quit;
%do i=1 %to &noobs;
%let leng&i. = %sysevalf(%length(&&var&i.)+1); %if %sysevalf(&&leng&i.) < 7 %then %let leng&i. = 7;
%do j=1 %to &number;
%if %length(%nrbquote(&&temp&i._&j.)) >= &&leng&i %then %do; %let temp&i._&j. = %qsubstr(%nrbquote(&&temp&i._&j.),1,%sysevalf(&&leng&i-2))~ ; %end;
%let tempx&i._&j. = %str(&&temp&i._&j. x);
%end;
%let varx&i. = %str(&&var&i. x);
%if &&type&i = 1 %then %do;
%let typex&i. = %str((num) x);
%end;
%if &&type&i = 2 %then %do;
%let typex&i. = %str((char) x);
%end;
%end;
%let numberofrows = 0;
%let ncoltab=0;
%do %until(&ncoltab=&noobs);
%let numberofrows=%sysevalf(&numberofrows+1);
%let findncoltab = 4;
%do %until(&findncoltab >= &linesize);
%let ncoltab=%sysevalf(&ncoltab+1);
%let findncoltab = %sysevalf(&findncoltab+&&leng&ncoltab.);
%if &findncoltab >= &linesize %then %let ncoltab=%sysevalf(&ncoltab-1);
%let ncoltab&numberofrows = &ncoltab;
%if &ncoltab=&noobs %then %let findncoltab = &linesize;
%end;
%end;
%do nrow=1 %to &numberofrows;
%let tabtop&nrow =%str( );
%let tabsec&nrow =%str( );
%do i=1 %to &number;
%if &i < 10 %then %do;
%let tab&nrow&i =#&i.%str( );
%end;
%else %do;
%let tab&nrow&i =#&i.%str( );
%end;
%end;
%end;
%let whatcol = 1;
%do nrow=1 %to &numberofrows;
%do i=&whatcol %to &&ncoltab&nrow;
%let whatcol = &i;
%let tabtop&nrow = &&tabtop&nrow%qsubstr(&&varx&i.,1,&&leng&i);
%let tabsec&nrow = &&tabsec&nrow%qsubstr(&&typex&i.,1,&&leng&i);
%do j=1 %to &number;
%let tab&nrow&j = &&tab&nrow&j%qsubstr(%nrbquote(&&tempx&i._&j.),1,&&leng&i);
%end;
%end;
%let whatcol = %sysevalf(&whatcol+1);
%end;
%put Table: &data;
%if &includefirstobs = yes %then %do;
%do nrow=1 %to &numberofrows;
%put &alotequal; %put &&tabtop&nrow; %put &&tabsec&nrow;
%do j=1 %to &number;
%put &&tab&nrow&j;
%end;
%end;
%end;
%else %do;
%put Number of variables: &noobs; %put ;
%do nrow=1 %to &numberofrows;
%put &&tabtop&nrow; %put &&tabsec&nrow; %put ;
%end;
%end;
%exit: %mend head;
%head(sashelp.baseball,obsnumber=5,includefirstobs=yes,linesize=90);